13 #ifndef __UT_NetSocket__
14 #define __UT_NetSocket__
36 UT_CONNECT_SUCCESS = 0,
40 UT_CONNECT_FAILED = -3,
41 UT_ERROR_OCCURED = -4,
48 UT_SHUTDOWN_RECEIVE = 0,
59 static const char *getErrorName(
int code);
61 static int getPortByService(
const char *service,
const char *proto=
"tcp",
62 int default_port = 0);
64 static void getHostName(
char *
name,
int max);
67 static int getHostAddress(
unsigned char address[4],
68 const char *hostname = 0);
72 static bool getHostNameByAlias(
UT_String &host,
const char *alias = NULL);
75 static int mapToUnprivilegedPort(
int port);
83 static bool sendCommandAndGetResult(
int port,
86 const char *host_name = 0,
87 bool remap_privileged_ports =
true);
89 static bool nonBlockingSendCommandAndGetResult(
int port,
92 const char *host_name = 0,
93 bool remap_privileged_ports =
true);
102 static UT_NetSocket *newSocket(
int port,
bool blocking =
false,
103 bool portisonlyhint =
false);
107 bool blocking =
false,
109 static void fdZero(fd_set *set);
110 static void fdSet(
int fd, fd_set *set);
111 static void fdClr(
int fd, fd_set *set);
112 static int fdIsSet(
int fd, fd_set *set);
128 static int select(
int fd, fd_set *r_set, fd_set *w_set,
131 static int selectInMS(
int maxfd,
137 bool isSocketSelected(fd_set &set);
139 void addToFDSet(fd_set *set,
int &maxfd);
144 virtual int64 getMemoryUsage(
bool inclusive)
const;
159 virtual int connect(
int timeout_ms = 0);
164 virtual int shutdown(
int type);
170 virtual int write(
const void *
data,
int len,
int *numWritten = 0);
175 virtual int dataAvailable(
int timeout=0);
189 virtual int read(
void *
data,
int len,
int *numRead = 0,
190 int timeout_ms = -1);
193 bool wait_for_null_terminator =
false);
196 virtual int peek(
void *
data,
int len,
int timeout_ms = -1);
199 virtual int flushRead();
200 virtual int flushWrite();
202 void terminateOnConnectionLost(
bool term =
true);
211 {
return myAddressName ? myAddressName:
""; }
214 {
return myAddressPort; }
218 virtual int getRemoteSocket(
char *host,
int &port)
const;
221 virtual int setBlocking(
bool blocking);
224 void setNoDelay(
int usenodelay);
228 void setQuickAck(
int quickack);
231 virtual int isValid();
239 int getSocket()
const;
242 bool getRemoteIP4(
int ip[4]);
243 uint32 getLocalIP4()
const;
244 bool getLocalIP4(
int ip[4]);
250 int socket,
bool blocking)
257 int closeInetSocket();
261 UT_NetSocket(
int port,
bool blocking =
false,
bool portisonlyhint=
false);
273 int waitForDataOrTimeout(
int timeout_ms );
279 int recv_(
void *
data,
int len,
int *num_read =
nullptr);
284 int connectOrTimeout(
struct sockaddr_in *
address,
285 int address_length,
int timeout_ms);
289 int doConnect(
struct sockaddr_in *
address,
290 int address_length,
bool check_err);
301 int checkDataStatus(
bool *fd_read,
bool *fd_write,
302 bool *fd_error,
int timeout_ms);
305 static bool commonGetHostNameByAlias(
UT_String &host,
316 unsigned char myIsServer :1,
struct timeval SYS_TimeVal
vint4 max(const vint4 &a, const vint4 &b)
uint32 getRemoteIP4() const
GLuint const GLchar * name
void read(T &in, bool &v)
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
GLuint GLuint64EXT address
virtual UT_UniquePtr< UT_NetSocket > createInstance(UT_NetSocket *sock, int socket, bool blocking)
vint4 select(const vbool4 &mask, const vint4 &a, const vint4 &b)
GLint GLenum GLsizei GLint GLsizei const void * data
const char * getAddress() const
GLuint GLuint GLsizei GLenum type
GLbitfield GLuint64 timeout
void write(T &out, bool v)
UT_AutoSocketDeleter(UT_NetSocket *socket)