1 #ifndef __SOCKET_TCP_H__
2 #define __SOCKET_TCP_H__
21 inline int SetNoDelay(
bool flag =
true);
22 inline int SetLinger(
int interval_seconds = 0);
23 inline int DontLinger();
24 inline int SetSendBufferSize(
int insize);
26 inline bool ActiveOpen(
const Socket_Address & theaddress,
bool setdelay);
27 inline bool ActiveOpenNonBlocking(
const Socket_Address & theaddress);
28 inline bool ErrorIs_WouldBlocking(
int err);
29 inline bool ShutdownSend();
30 inline int SendData(
const std::string &str);
33 std::string RecvData(
int max_len);
35 inline int SendData(
const char * data,
int size);
36 inline int RecvData(
char * data,
int size);
42 static void init_type() {
43 Socket_IP::init_type();
44 register_type(_type_handle,
"Socket_TCP",
45 Socket_IP::get_class_type());
48 return get_class_type();
50 virtual TypeHandle force_init_type() {init_type();
return get_class_type();}
60 inline Socket_TCP::Socket_TCP(SOCKET sck) : ::
Socket_IP(sck)
72 ret1 = setsockopt(_socket, IPPROTO_TCP, TCP_NODELAY, (
char *) & nodel,
sizeof(nodel));
87 ll.l_linger = interval_seconds;
89 int ret1 = setsockopt(_socket, SOL_SOCKET, SO_LINGER, (
const char *) & ll,
sizeof(linger));
107 int ret1 = setsockopt(_socket, SOL_SOCKET, SO_LINGER, (
const char *) & ll,
sizeof(linger));
121 if (setsockopt(_socket, (
int) SOL_SOCKET, (
int) SO_SNDBUF, (
char *) &insize,
sizeof(
int)))
133 _socket = DO_NEWTCP();
134 if (_socket == BAD_SOCKET)
140 if (DO_CONNECT(_socket, &theaddress.GetAddressInfo()) != 0)
154 _socket = DO_NEWTCP();
155 if (_socket == BAD_SOCKET)
161 if (DO_CONNECT(_socket, &theaddress.GetAddressInfo()) != 0) {
162 if (GETERROR() != LOCAL_CONNECT_BLOCKING)
164 printf(
" None Blockign Connect Error %d",GETERROR());
181 inline int Socket_TCP::SendData(
const char * data,
int size)
183 return DO_SOCKET_WRITE(_socket, data, size);
197 int ecode = DO_SOCKET_READ(_socket, data, len);
213 char *buffer = (
char *) malloc(max_len+1);
214 int ecode =
RecvData(buffer,max_len);
216 str.assign(buffer,ecode);
223 inline bool Socket_TCP::ErrorIs_WouldBlocking(
int err)
225 return (GETERROR() == LOCAL_BLOCKING_ERROR);
228 inline bool Socket_TCP::ShutdownSend()
230 return do_shutdown_send(_socket);
243 inline int Socket_TCP::SendData(
const std::string &str)
245 return SendData(str.data(), str.size());
248 #endif //__SOCKET_TCP_H__
Base functionality for a TCP connected socket This class is pretty useless by itself but it does hide...
Base functionality for a INET domain Socket this call should be the starting point for all other unix...
int SetNonBlocking()
this function will throw a socket into non-blocking mode
std::string RecvData(int max_len)
Read the data from the connection.
bool ActiveOpenNonBlocking(const Socket_Address &theaddress)
This function will try and set the socket up for active open to a specified address and port provided...
int DontLinger()
Turn off the linger flag.
A simple place to store and munipulate tcp and port address for communication layer.
int SetLinger(int interval_seconds=0)
will control the behavior of SO_LINGER for a TCP socket
bool SetReuseAddress(bool flag=true)
Informs a socket to reuse IP address as needed.
TypeHandle is the identifier used to differentiate C++ class types.
bool ActiveOpen(const Socket_Address &theaddress, bool setdelay)
This function will try and set the socket up for active open to a specified address and port provided...
int SetSendBufferSize(int insize)
Just like it sounds.
int SetNoDelay(bool flag=true)
Disable Nagle algorithm.