diff options
author | Luo Jinghua <sunmoon1997@gmail.com> | 2011-11-27 09:39:29 +0800 |
---|---|---|
committer | Luo Jinghua <sunmoon1997@gmail.com> | 2011-11-27 09:39:29 +0800 |
commit | b23b56ea0d2a651ac95c8db4ad9a97da23592cd6 (patch) | |
tree | 94cf6b531409950cc27550682c16c790d4a22fab | |
parent | b636c405e5e2dd6e5a9f3ecce9117a659049ff47 (diff) |
SexyAppFramework: Allow to create a bare TCPServerSocket
-rw-r--r-- | osframework/source/SexyAppFramework/SexySocket.cpp | 9 | ||||
-rw-r--r-- | osframework/source/SexyAppFramework/SexySocket.h | 14 |
2 files changed, 22 insertions, 1 deletions
diff --git a/osframework/source/SexyAppFramework/SexySocket.cpp b/osframework/source/SexyAppFramework/SexySocket.cpp index 9359578..fbbb5b7 100644 --- a/osframework/source/SexyAppFramework/SexySocket.cpp +++ b/osframework/source/SexyAppFramework/SexySocket.cpp @@ -143,7 +143,10 @@ bool Socket::setLocalAddressAndPort(const string &localAddress, fillAddr(localAddress, localPort, localAddr); if (bind(mSock, (sockaddr *) &localAddr, sizeof(sockaddr_in)) < 0) + { + printf("Bind error: %s\n", strerror(errno)); return false; + } return true; } @@ -280,6 +283,12 @@ TCPSocket::TCPSocket(int newConnSD) : CommunicatingSocket(newConnSD) // TCPServerSocket Code +TCPServerSocket::TCPServerSocket(int queueLen) + : Socket(SOCK_STREAM, IPPROTO_TCP) +{ + setAddressReuse(true); +} + TCPServerSocket::TCPServerSocket(unsigned short localPort, int queueLen) : Socket(SOCK_STREAM, IPPROTO_TCP) { diff --git a/osframework/source/SexyAppFramework/SexySocket.h b/osframework/source/SexyAppFramework/SexySocket.h index 8383b21..900d0af 100644 --- a/osframework/source/SexyAppFramework/SexySocket.h +++ b/osframework/source/SexyAppFramework/SexySocket.h @@ -185,6 +185,13 @@ namespace Sexy { class TCPServerSocket : public Socket { public: /** + * Construct a TCP socket for use with a server. + * @param queueLen maximum queue length for outstanding + * connection requests (default 5) + */ + TCPServerSocket(int queueLen = 5); + + /** * Construct a TCP socket for use with a server, accepting connections * on the specified port on any interface * @param localPort local port of server socket, a value of zero will @@ -211,7 +218,12 @@ namespace Sexy { */ TCPSocket *accept(); - private: + + /** + * Listen for connections for the socket + * @param queueLen maximum queue length for outstanding + * @return true on success + */ bool setListen(int queueLen); }; |