Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tcp server #43

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ static int createIPServerSocket(const char* port, addrinfo const& hints)
if (sfd == -1)
continue;

int option = 1;
setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &option, sizeof(option));
Comment on lines +346 to +347
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't REUSEADDR by default.

You can use the URI options to enable it optionally if you'd like to.


if (::bind(sfd, rp->ai_addr, rp->ai_addrlen) == 0) {
return sfd;
}
Expand Down
5 changes: 4 additions & 1 deletion src/IOStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,11 @@ TCPServerStream::TCPServerStream(int socket_fd)

TCPServerStream::~TCPServerStream() {
if(m_client_fd) {
close(m_client_fd);
std::cout << "~TCPServerStream:: close client connection" << std::endl;
::close(m_client_fd);
}
std::cout << "~TCPServerStream:: close server socket" << std::endl;
::close(m_fd);
}

int TCPServerStream::getFileDescriptor() const { return m_client_fd; }
Expand Down