15
15
16
16
namespace fineftp
17
17
{
18
- std::shared_ptr<FtpServerImpl> FtpServerImpl::create (const std::string& address, uint16_t port)
18
+ std::shared_ptr<FtpServerImpl> FtpServerImpl::create (const std::string& address, uint16_t port, std::ostream& output, std::ostream& error )
19
19
{
20
- return std::shared_ptr<FtpServerImpl>(new FtpServerImpl (address, port));
20
+ return std::shared_ptr<FtpServerImpl>(new FtpServerImpl (address, port, output, error ));
21
21
}
22
22
23
23
FtpServerImpl::FtpServerImpl (const std::string& address, const uint16_t port, std::ostream& output, std::ostream& error)
@@ -68,18 +68,17 @@ namespace fineftp
68
68
}
69
69
}
70
70
71
- // TODO: Add the code again to use reuse_address option
72
- // {
73
- // const std::lock_guard<std::mutex> acceptor_lock(acceptor_mutex_);
74
-
75
- // asio::error_code ec;
76
- // acceptor_.set_option(asio::ip::tcp::acceptor::reuse_address(true), ec);
77
- // if (ec)
78
- // {
79
- // std::cerr << "Error setting reuse_address option: " << ec.message() << std::endl;
80
- // return false;
81
- // }
82
- // }
71
+ {
72
+ const std::lock_guard<std::mutex> acceptor_lock (acceptor_mutex_);
73
+
74
+ asio::error_code ec;
75
+ acceptor_.set_option (asio::ip::tcp::acceptor::reuse_address (true ), ec);
76
+ if (ec)
77
+ {
78
+ error_ << " Error setting reuse_address option: " << ec.message () << std::endl;
79
+ return false ;
80
+ }
81
+ }
83
82
84
83
{
85
84
const std::lock_guard<std::mutex> acceptor_lock (acceptor_mutex_);
@@ -178,7 +177,7 @@ namespace fineftp
178
177
}
179
178
};
180
179
181
- auto new_ftp_session = std::make_shared<FtpSession>(io_service_, ftp_users_, shutdown_callback);
180
+ auto new_ftp_session = std::make_shared<FtpSession>(io_service_, ftp_users_, shutdown_callback, output_, error_ );
182
181
183
182
{
184
183
const std::lock_guard<std::mutex> acceptor_lock (acceptor_mutex_);
@@ -205,7 +204,7 @@ namespace fineftp
205
204
}
206
205
207
206
#ifndef NDEBUG
208
- output_ << " FTP Client connected: " << new_ftp_session->getSocket ().remote_endpoint ().address ().to_string () << " :" << new_ftp_session->getSocket ().remote_endpoint ().port () << std::endl;
207
+ me-> output_ << " FTP Client connected: " << new_ftp_session->getSocket ().remote_endpoint ().address ().to_string () << " :" << new_ftp_session->getSocket ().remote_endpoint ().port () << std::endl;
209
208
#endif
210
209
// TODO: review if this is thread safe, if right here the ftp server is shut down and the acceptor is closed. I think, that then the session will still be added to the list of open sessions and kept open.
211
210
0 commit comments