The qDecoder Project

qSocket.c File Reference

Socket Handling API. More...


Functions

int qSocketOpen (const char *hostname, int port, int timeoutms)
 Create a TCP socket for the remote host and port.
bool qSocketClose (int sockfd, int timeoutms)
 Close socket.
bool qSocketGetAddr (struct sockaddr_in *addr, const char *hostname, int port)
 Convert hostname to sockaddr_in structure.


Detailed Description

Socket Handling API.


Function Documentation

int qSocketOpen ( const char *  hostname,
int  port,
int  timeoutms 
)

Create a TCP socket for the remote host and port.

Parameters:
hostname remote hostname
port remote port
timeoutms wait timeout milliseconds. if set to negative value, wait indefinitely.
Returns:
the new socket descriptor, or -1 in case of invalid hostname, -2 in case of socket creation failure, -3 in case of connection failure.

bool qSocketClose ( int  sockfd,
int  timeoutms 
)

Close socket.

Parameters:
sockfd socket descriptor
timeoutms if timeoutms >= 0, shut down write connection first then wait and throw out input stream data. set to -1 to close socket immediately.
Returns:
true on success, or false if an error occurred.

bool qSocketGetAddr ( struct sockaddr_in *  addr,
const char *  hostname,
int  port 
)

Convert hostname to sockaddr_in structure.

Parameters:
addr sockaddr_in structure pointer
hostname IP string address or hostname
port port number
Returns:
true if successful, otherwise returns false.


Copyright (c) 2008 The qDecoder Project