1 #ifndef __SOCKET_IP_H__ 2 #define __SOCKET_IP_H__ 5 #include "socket_portable.h" 35 inline static int GetLastError();
36 inline int SetNonBlocking();
37 inline int SetBlocking();
38 inline bool SetReuseAddress(
bool flag =
true);
39 inline bool SetV6Only(
bool flag);
41 inline int SetRecvBufferSize(
int size);
42 inline void SetSocket(SOCKET ins);
43 inline SOCKET GetSocket();
44 inline SOCKET GetSocket()
const;
47 inline static int InitNetworkDriver() {
return init_network(); };
50 inline bool ErrorClose();
59 friend class Socket_TCP_SSL;
68 TypedObject::get_class_type());
71 return get_class_type();
82 inline bool Socket_IP::
97 return (_socket != BAD_SOCKET);
105 _socket = BAD_SOCKET;
133 _socket = BAD_SOCKET;
158 if (setsockopt(_socket, (
int) SOL_SOCKET, (
int) SO_RCVBUF, (
char *) &insize,
sizeof(
int))) {
171 int flags = fcntl(_socket, F_GETFL, 0);
172 flags = flags | O_NONBLOCK;
173 fcntl(_socket, F_SETFL, flags);
176 unsigned long val = LOCAL_NONBLOCK;
177 unsigned lanswer = 0;
178 lanswer = SOCKIOCTL(_socket, LOCAL_FL_SET, &val);
193 int flags = fcntl(_socket, F_GETFL, 0);
194 flags &= ~O_NONBLOCK;
195 fcntl(_socket, F_SETFL, flags);
198 unsigned long val = 0;
199 unsigned lanswer = 0;
200 lanswer = SOCKIOCTL(_socket, LOCAL_FL_SET, &val);
214 if (setsockopt(_socket, SOL_SOCKET, SO_REUSEADDR, (
const char *)&value,
sizeof(value)) != 0) {
226 int value = flag ? 1 : 0;
227 if (setsockopt(_socket, IPPROTO_IPV6, IPV6_V6ONLY, (
const char *)&value,
sizeof(value))) {
254 sockaddr_storage name;
255 socklen_t name_len =
sizeof(name);
256 memset(&name, 0, name_len);
258 getpeername(_socket, (sockaddr *)&name, &name_len);
262 #endif //__SOCKET_IP_H__ int SetRecvBufferSize(int size)
Ok it sets the recv buffer size for both tcp and UDP.
Base functionality for a TCP connected socket This class is pretty useless by itself but it does hide...
static void init_type()
This function is declared non-inline to work around a compiler bug in g++ 2.96.
Base functionality for a INET domain Socket This call should be the starting point for all other unix...
int SetBlocking()
Set the socket to block on subsequent calls to socket functions that address this socket.
int SetNonBlocking()
this function will throw a socket into non-blocking mode
Base functionality for a UDP sending socket.
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 SetV6Only(bool flag)
Sets a flag indicating whether this IPv6 socket should operate in dual-stack mode or not.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is an abstract class that all classes which use TypeHandle, and also provide virtual functions t...
Socket_Address GetPeerName(void) const
Wrapper on berkly getpeername...
bool Active()
Ask if the socket is open (allocated)
Base functionality for a TCP rendezvous socket.
void SetSocket(SOCKET ins)
Assigns an existing socket to this class.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Base functionality for a combination UDP Reader and Writer.
Base functionality for a UDP Reader.
virtual ~Socket_IP()
Destructor.
A simple place to store and manipulate tcp and port address for communication layer.
Socket_IP()
Def Constructor.
static int GetLastError()
Gets the last errcode from a socket operation.
bool SetReuseAddress(bool flag=true)
Informs a socket to reuse IP address as needed.
void Close()
Closes a socket if it is open (allocated).
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
SOCKET GetSocket()
Gets the base socket type.