Socket handling APIs.
More...
Go to the source code of this file.
|
| int | qsocket_open (const char *hostname, int port, int timeoutms) |
| | Create a TCP socket for a remote host and port.
|
| bool | qsocket_close (int sockfd, int timeoutms) |
| | Close socket.
|
| bool | qsocket_get_addr (struct sockaddr_in *addr, const char *hostname, int port) |
| | Convert a hostname to a sockaddr_in structure.
|
| char * | qsocket_get_localaddr (char *buf, size_t bufsize) |
| | Get the local IP address.
|
Socket handling APIs.
Definition in file qsocket.c.
◆ qsocket_open()
| int qsocket_open |
( |
const char * | hostname, |
|
|
int | port, |
|
|
int | timeoutms ) |
Create a TCP socket for a remote host and port.
- Parameters
-
| hostname | remote hostname |
| port | remote port |
| timeoutms | wait timeout in milliseconds. If negative, wait forever. |
- Returns
- the new socket descriptor, or: -1 if the hostname is invalid -2 if socket creation fails -3 if the connection fails
Definition at line 64 of file qsocket.c.
◆ qsocket_close()
| bool qsocket_close |
( |
int | sockfd, |
|
|
int | timeoutms ) |
Close socket.
- Parameters
-
| sockfd | socket descriptor |
| timeoutms | if timeoutms >= 0, shut down the write side first, then wait and discard incoming data. Set to -1 to close the socket immediately. |
- Returns
- true on success, or false if an error occurred.
Definition at line 108 of file qsocket.c.
◆ qsocket_get_addr()
| bool qsocket_get_addr |
( |
struct sockaddr_in * | addr, |
|
|
const char * | hostname, |
|
|
int | port ) |
Convert a hostname to a sockaddr_in structure.
- Parameters
-
| addr | sockaddr_in output pointer |
| hostname | IP address string or hostname |
| port | port number |
- Returns
- true on success, otherwise false.
Definition at line 134 of file qsocket.c.
◆ qsocket_get_localaddr()
| char * qsocket_get_localaddr |
( |
char * | buf, |
|
|
size_t | bufsize ) |
Get the local IP address.
- Returns
- pointer to buf on success, or NULL on failure.
Definition at line 154 of file qsocket.c.