1 #ifndef __SOCKET_TCP_H__ 2 #define __SOCKET_TCP_H__ 16 inline int SetNoDelay(
bool flag =
true);
17 inline int SetLinger(
int interval_seconds = 0);
18 inline int DontLinger();
19 inline int SetSendBufferSize(
int insize);
21 inline bool ActiveOpen(
const Socket_Address &theaddress,
bool setdelay);
22 inline bool ActiveOpenNonBlocking(
const Socket_Address &theaddress);
23 inline bool ErrorIs_WouldBlocking(
int err);
24 inline bool ShutdownSend();
25 inline int SendData(
const std::string &str);
28 std::string RecvData(
int max_len);
30 inline int SendData(
const char *data,
int size);
31 inline int RecvData(
char *data,
int size);
37 static void init_type() {
38 Socket_IP::init_type();
40 Socket_IP::get_class_type());
43 return get_class_type();
45 virtual TypeHandle force_init_type() {init_type();
return get_class_type();}
55 Socket_TCP(SOCKET sck) : ::
Socket_IP(sck) {
63 int value = flag ? 1 : 0;
64 if (setsockopt(_socket, IPPROTO_TCP, TCP_NODELAY, (
const char *)&value,
sizeof(value))) {
76 ll.l_linger = interval_seconds;
78 int ret1 = setsockopt(_socket, SOL_SOCKET, SO_LINGER, (
const char *)&ll,
sizeof(linger));
95 int ret1 = setsockopt(_socket, SOL_SOCKET, SO_LINGER, (
const char *)&ll,
sizeof(linger));
108 if (setsockopt(_socket, SOL_SOCKET, SO_SNDBUF, (
char *)&insize,
sizeof(
int))) {
121 if (_socket == BAD_SOCKET) {
129 if (DO_CONNECT(_socket, &theaddress.GetAddressInfo()) != 0) {
144 if (_socket == BAD_SOCKET) {
151 if (DO_CONNECT(_socket, &theaddress.GetAddressInfo()) != 0) {
152 if (GETERROR() != LOCAL_CONNECT_BLOCKING) {
153 printf(
"Non Blocking Connect Error %d", GETERROR());
165 inline int Socket_TCP::
166 SendData(
const char *data,
int size) {
167 return DO_SOCKET_WRITE(_socket, data, size);
176 int ecode = DO_SOCKET_READ(_socket, data, len);
187 char *buffer = (
char *)malloc(max_len + 1);
188 int ecode =
RecvData(buffer, max_len);
190 str.assign(buffer, ecode);
198 inline bool Socket_TCP::
199 ErrorIs_WouldBlocking(
int err) {
200 return (GETERROR() == LOCAL_BLOCKING_ERROR);
203 inline bool Socket_TCP::
205 return do_shutdown_send(_socket);
219 inline int Socket_TCP::
220 SendData(
const std::string &str) {
221 return SendData(str.data(), str.size());
224 #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 - if error 0 if socket closed for read or length is 0 + bytes read ...
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
sa_family_t get_family() const
Returns AF_INET if this is an IPv4 address, or AF_INET6 if this is an IPv6 address.
A simple place to store and manipulate 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.