13 #ifndef __UT_NetSocket__
14 #define __UT_NetSocket__
32 template <
typename T>
class UT_Array;
43 UT_CONNECT_SUCCESS = 0,
47 UT_CONNECT_FAILED = -3,
48 UT_ERROR_OCCURED = -4,
55 UT_SHUTDOWN_RECEIVE = 0,
66 static const char *getErrorName(
int code);
68 static int getPortByService(
const char *service,
const char *proto=
"tcp",
69 int default_port = 0);
71 static void getHostName(
char *
name,
int max);
74 static bool getHostAddress(
76 const char *hostname = 0);
78 static bool getHostAddress(
UT_IpAddress &address,
const char *hostname = 0);
87 static bool getHostNameByAlias(
UT_String &host,
const char *alias = NULL);
90 static int mapToUnprivilegedPort(
int port);
98 static bool sendCommandAndGetResult(
int port,
101 const char *host_name = 0,
102 bool remap_privileged_ports =
true);
104 static bool nonBlockingSendCommandAndGetResult(
int port,
107 const char *host_name = 0,
108 bool remap_privileged_ports =
true);
118 bool portisonlyhint =
false);
122 bool blocking =
false,
124 static void fdZero(fd_set *set);
125 static void fdSet(
int fd, fd_set *set);
126 static void fdClr(
int fd, fd_set *set);
127 static int fdIsSet(
int fd, fd_set *set);
143 static int select(
int fd, fd_set *r_set, fd_set *w_set,
146 static int selectInMS(
int maxfd,
152 bool isSocketSelected(fd_set &set);
154 void addToFDSet(fd_set *set,
int &maxfd);
159 virtual int64 getMemoryUsage(
bool inclusive)
const;
174 virtual int connect(
int timeout_ms = 0);
179 return closeInetSocket();
182 virtual int shutdown(
int type);
188 virtual int write(
const void *
data,
int len,
int *numWritten = 0);
193 virtual int dataAvailable(
int timeout=0);
207 virtual int read(
void *
data,
int len,
int *numRead = 0,
208 int timeout_ms = -1);
211 bool wait_for_null_terminator =
false);
214 virtual int peek(
void *
data,
int len,
int timeout_ms = -1);
217 virtual int flushRead();
218 virtual int flushWrite();
220 void terminateOnConnectionLost(
bool term =
true);
229 {
return myAddressName ? myAddressName:
""; }
232 {
return myAddressPort; }
235 virtual int getRemoteSocket(
UT_IpAddressV4& host,
int &port)
const;
238 virtual int setBlocking(
bool blocking);
241 void setNoDelay(
int usenodelay);
245 void setQuickAck(
int quickack);
248 virtual bool isValid()
const {
return mySocket != -1; }
271 int sockRecv(
void *
data,
int len,
int *num_read =
nullptr);
275 int closeInetSocket();
279 UT_NetSocket(
const char *address,
int port,
bool blocking =
false,
290 int waitForDataOrTimeout(
int timeout_ms );
297 int connectOrTimeout(
struct sockaddr_in *address,
298 int address_length,
int timeout_ms);
302 int doConnect(
struct sockaddr_in *address,
303 int address_length,
bool check_err);
305 bool setupAsServer(
int port,
bool blocking,
bool portisonlyhint);
314 int checkDataStatus(
bool *fd_read,
bool *fd_write,
315 bool *fd_error,
int timeout_ms);
325 unsigned char myIsServer :1,
344 UT_NetSocket *mySocket;
struct timeval SYS_TimeVal
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
#define SYS_DEPRECATED_PUSH_DISABLE()
This represents a Ipv4 address.
#define SYS_DEPRECATED_POP_DISABLE()
virtual bool isValid() const
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
#define SYS_DEPRECATED_REPLACE(__V__, __R__)
This represents either an Ipv4 address or an Ipv6 address.
vint4 select(const vbool4 &mask, const vint4 &a, const vint4 &b)
GLbitfield GLuint64 timeout
UT_IpAddressV4 myRemoteIP4
const char * getAddress() const
#define SYS_NO_DISCARD_RESULT
GLuint const GLchar * name
LeafData & operator=(const LeafData &)=delete
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
UT_UniquePtr< UT_NetSocket > UT_NetSocketPtr
const UT_IpAddressV4 & getRemoteIP4() const
UT_AutoSocketDeleter(UT_NetSocket *socket)