Add parameters specify tcp server bind ip address (#1287)
This commit is contained in:
parent
ea8c57fea3
commit
a49c8676d8
@ -11,7 +11,10 @@
|
|||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
TcpListener::TcpListener(int port, ActorShared<Callback> callback) : port_(port), callback_(std::move(callback)) {
|
|
||||||
|
|
||||||
|
TcpListener::TcpListener(int port, ActorShared<Callback> callback, Slice server_address) :
|
||||||
|
port_(port), callback_(std::move(callback)), server_address_(server_address.str()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TcpListener::hangup() {
|
void TcpListener::hangup() {
|
||||||
@ -19,7 +22,7 @@ void TcpListener::hangup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TcpListener::start_up() {
|
void TcpListener::start_up() {
|
||||||
auto r_socket = ServerSocketFd::open(port_);
|
auto r_socket = ServerSocketFd::open(port_, server_address_);
|
||||||
if (r_socket.is_error()) {
|
if (r_socket.is_error()) {
|
||||||
LOG(ERROR) << "Can't open server socket: " << r_socket.error();
|
LOG(ERROR) << "Can't open server socket: " << r_socket.error();
|
||||||
set_timeout_in(5);
|
set_timeout_in(5);
|
||||||
|
@ -20,13 +20,14 @@ class TcpListener final : public Actor {
|
|||||||
virtual void accept(SocketFd fd) = 0;
|
virtual void accept(SocketFd fd) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
TcpListener(int port, ActorShared<Callback> callback);
|
TcpListener(int port, ActorShared<Callback> callback, Slice server_address = Slice("0.0.0.0"));
|
||||||
void hangup() override;
|
void hangup() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int port_;
|
int port_;
|
||||||
ServerSocketFd server_fd_;
|
ServerSocketFd server_fd_;
|
||||||
ActorShared<Callback> callback_;
|
ActorShared<Callback> callback_;
|
||||||
|
const string server_address_;
|
||||||
void start_up() override;
|
void start_up() override;
|
||||||
void tear_down() override;
|
void tear_down() override;
|
||||||
void loop() override;
|
void loop() override;
|
||||||
|
Loading…
Reference in New Issue
Block a user