13 #ifndef __UT_NetSocket__
14 #define __UT_NetSocket__
37 UT_CONNECT_SUCCESS = 0,
41 UT_CONNECT_FAILED = -3,
42 UT_ERROR_OCCURED = -4,
49 UT_SHUTDOWN_RECEIVE = 0,
60 static const char *getErrorName(
int code);
62 static int getPortByService(
const char *service,
const char *proto=
"tcp",
63 int default_port = 0);
65 static void getHostName(
char *
name,
int max);
69 const char *hostname = 0);
77 if (!getLocalAddresses(ips, family) || ips.
isEmpty())
86 static bool getHostNameByAlias(
UT_String &host,
const char *alias = NULL);
89 static int mapToUnprivilegedPort(
int port);
97 static bool sendCommandAndGetResult(
int port,
100 const char *host_name = 0,
101 bool remap_privileged_ports =
true);
103 static bool nonBlockingSendCommandAndGetResult(
int port,
106 const char *host_name = 0,
107 bool remap_privileged_ports =
true);
117 bool portisonlyhint =
false);
121 bool blocking =
false,
123 static void fdZero(fd_set *set);
124 static void fdSet(
int fd, fd_set *set);
125 static void fdClr(
int fd, fd_set *set);
126 static int fdIsSet(
int fd, fd_set *set);
142 static int select(
int fd, fd_set *r_set, fd_set *w_set,
145 static int selectInMS(
int maxfd,
151 bool isSocketSelected(fd_set &set);
153 void addToFDSet(fd_set *set,
int &maxfd);
158 virtual int64 getMemoryUsage(
bool inclusive)
const;
173 virtual int connect(
int timeout_ms = 0);
178 return closeInetSocket();
181 virtual int shutdown(
int type);
187 virtual int write(
const void *
data,
int len,
int *numWritten = 0);
192 virtual int dataAvailable(
int timeout=0);
206 virtual int read(
void *
data,
int len,
int *numRead = 0,
207 int timeout_ms = -1);
210 bool wait_for_null_terminator =
false);
213 virtual int peek(
void *
data,
int len,
int timeout_ms = -1);
216 virtual int flushRead();
217 virtual int flushWrite();
219 void terminateOnConnectionLost(
bool term =
true);
228 {
return myAddressName ? myAddressName:
""; }
231 {
return myAddressPort; }
234 virtual int getRemoteSocket(
UT_IpAddressV4& host,
int &port)
const;
237 virtual int setBlocking(
bool blocking);
240 void setNoDelay(
int usenodelay);
244 void setQuickAck(
int quickack);
247 virtual bool isValid()
const {
return mySocket != -1; }
270 int sockRecv(
void *
data,
int len,
int *num_read =
nullptr);
274 int closeInetSocket();
289 int waitForDataOrTimeout(
int timeout_ms );
296 int connectOrTimeout(
struct sockaddr_in *
address,
297 int address_length,
int timeout_ms);
301 int doConnect(
struct sockaddr_in *
address,
302 int address_length,
bool check_err);
304 bool setupAsServer(
int port,
bool blocking,
bool portisonlyhint);
313 int checkDataStatus(
bool *fd_read,
bool *fd_write,
314 bool *fd_error,
int timeout_ms);
324 unsigned char myIsServer :1,
struct timeval SYS_TimeVal
This represents a Ipv4 address.
GLuint const GLchar * name
virtual bool isValid() const
void read(T &in, bool &v)
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
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 GLuint64EXT address
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
void write(T &out, bool v)
static bool getLocalAddress(UT_IpAddress &address, UT_IpAddressFamily family=UT_IpAddressFamily::IPv4)
const UT_IpAddressV4 & getRemoteIP4() const
UT_AutoSocketDeleter(UT_NetSocket *socket)
bool isEmpty() const
Returns true iff there are no occupied elements in the array.