change port type to uint16_t

pull/37/head
YuQing 2020-09-27 08:46:46 +08:00
parent 55fc4013b3
commit 082a322f3d
3 changed files with 17 additions and 17 deletions

View File

@ -36,7 +36,7 @@ extern "C" {
typedef struct typedef struct
{ {
int sock; int sock;
short port; uint16_t port;
short socket_domain; //socket domain, AF_INET, AF_INET6 or AF_UNSPEC for auto dedect short socket_domain; //socket domain, AF_INET, AF_INET6 or AF_UNSPEC for auto dedect
bool validate_flag; //for connection pool bool validate_flag; //for connection pool
char ip_addr[INET6_ADDRSTRLEN]; char ip_addr[INET6_ADDRSTRLEN];
@ -306,7 +306,7 @@ static inline void conn_pool_set_server_info(ConnectionInfo *pServerInfo,
} }
static inline int conn_pool_compare_ip_and_port(const char *ip1, static inline int conn_pool_compare_ip_and_port(const char *ip1,
const short port1, const char *ip2, const short port2) const int port1, const char *ip2, const int port2)
{ {
int result; int result;
if ((result=strcmp(ip1, ip2)) != 0) { if ((result=strcmp(ip1, ip2)) != 0) {

View File

@ -471,7 +471,7 @@ int tcpsenddata_nb(int sock, void* data, const int size, const int timeout)
return 0; return 0;
} }
int setsockaddrbyip(const char *ip, const short port, sockaddr_convert_t *convert) int setsockaddrbyip(const char *ip, const uint16_t port, sockaddr_convert_t *convert)
{ {
int af; int af;
void *dest; void *dest;
@ -505,7 +505,7 @@ int setsockaddrbyip(const char *ip, const short port, sockaddr_convert_t *conver
return 0; return 0;
} }
int connectserverbyip(int sock, const char *server_ip, const short server_port) int connectserverbyip(int sock, const char *server_ip, const uint16_t server_port)
{ {
int result; int result;
sockaddr_convert_t convert; sockaddr_convert_t convert;
@ -524,7 +524,7 @@ int connectserverbyip(int sock, const char *server_ip, const short server_port)
} }
int connectserverbyip_nb_ex(int sock, const char *server_ip, \ int connectserverbyip_nb_ex(int sock, const char *server_ip, \
const short server_port, const int timeout, \ const uint16_t server_port, const int timeout, \
const bool auto_detect) const bool auto_detect)
{ {
int result; int result;
@ -636,7 +636,7 @@ int connectserverbyip_nb_ex(int sock, const char *server_ip, \
} }
int asyncconnectserverbyip(int sock, const char *server_ip, int asyncconnectserverbyip(int sock, const char *server_ip,
const short server_port) const uint16_t server_port)
{ {
int result; int result;
sockaddr_convert_t convert; sockaddr_convert_t convert;
@ -701,7 +701,7 @@ int socketCreateEx2(int af, const char *server_ip,
} }
int socketClientEx2(int af, const char *server_ip, int socketClientEx2(int af, const char *server_ip,
const short server_port, const int timeout, const uint16_t server_port, const int timeout,
const int flags, const char *bind_ipaddr, int *err_no) const int flags, const char *bind_ipaddr, int *err_no)
{ {
int sock; int sock;

View File

@ -171,7 +171,7 @@ int tcpsenddata_nb(int sock, void* data, const int size, const int timeout);
* server_port: port of the server * server_port: port of the server
* return: error no, 0 success, != 0 fail * return: error no, 0 success, != 0 fail
*/ */
int connectserverbyip(int sock, const char *server_ip, const short server_port); int connectserverbyip(int sock, const char *server_ip, const uint16_t server_port);
/** connect to server by non-block mode /** connect to server by non-block mode
* parameters: * parameters:
@ -183,7 +183,7 @@ int connectserverbyip(int sock, const char *server_ip, const short server_port);
* return: error no, 0 success, != 0 fail * return: error no, 0 success, != 0 fail
*/ */
int connectserverbyip_nb_ex(int sock, const char *server_ip, \ int connectserverbyip_nb_ex(int sock, const char *server_ip, \
const short server_port, const int timeout, \ const uint16_t server_port, const int timeout, \
const bool auto_detect); const bool auto_detect);
/** connect to server by non-block mode, the socket must be set to non-block /** connect to server by non-block mode, the socket must be set to non-block
@ -217,7 +217,7 @@ int connectserverbyip_nb_ex(int sock, const char *server_ip, \
* return: error no, 0 or EINPROGRESS for success, others for fail * return: error no, 0 or EINPROGRESS for success, others for fail
*/ */
int asyncconnectserverbyip(int sock, const char *server_ip, int asyncconnectserverbyip(int sock, const char *server_ip,
const short server_port); const uint16_t server_port);
/** accept client connect request /** accept client connect request
* parameters: * parameters:
@ -414,7 +414,7 @@ static inline int socketCreateExAuto(const char *server_ip,
* return: >= 0 server socket, < 0 fail * return: >= 0 server socket, < 0 fail
*/ */
int socketClientEx2(int af, const char *server_ip, int socketClientEx2(int af, const char *server_ip,
const short server_port, const int timeout, const uint16_t server_port, const int timeout,
const int flags, const char *bind_ipaddr, int *err_no); const int flags, const char *bind_ipaddr, int *err_no);
/** connect to server /** connect to server
@ -428,7 +428,7 @@ int socketClientEx2(int af, const char *server_ip,
* return: >= 0 server socket, < 0 fail * return: >= 0 server socket, < 0 fail
*/ */
static inline int socketClientExAuto(const char *server_ip, static inline int socketClientExAuto(const char *server_ip,
const short server_port, const int timeout, const uint16_t server_port, const int timeout,
const int flags, const char *bind_ipaddr, int *err_no) const int flags, const char *bind_ipaddr, int *err_no)
{ {
return socketClientEx2(AF_UNSPEC, server_ip, server_port, return socketClientEx2(AF_UNSPEC, server_ip, server_port,
@ -446,7 +446,7 @@ static inline int socketClientExAuto(const char *server_ip,
* return: >= 0 server socket, < 0 fail * return: >= 0 server socket, < 0 fail
*/ */
static inline int socketClientAuto(const char *server_ip, static inline int socketClientAuto(const char *server_ip,
const short server_port, const int timeout, const uint16_t server_port, const int timeout,
const int flags, int *err_no) const int flags, int *err_no)
{ {
return socketClientEx2(AF_UNSPEC, server_ip, server_port, return socketClientEx2(AF_UNSPEC, server_ip, server_port,
@ -464,7 +464,7 @@ static inline int socketClientAuto(const char *server_ip,
* return: >= 0 server socket, < 0 fail * return: >= 0 server socket, < 0 fail
*/ */
static inline int socketClient2(int af, const char *server_ip, static inline int socketClient2(int af, const char *server_ip,
const short server_port, const int timeout, const uint16_t server_port, const int timeout,
const int flags, int *err_no) const int flags, int *err_no)
{ {
return socketClientEx2(af, server_ip, server_port, return socketClientEx2(af, server_ip, server_port,
@ -481,7 +481,7 @@ static inline int socketClient2(int af, const char *server_ip,
* return: >= 0 server socket, < 0 fail * return: >= 0 server socket, < 0 fail
*/ */
static inline int socketClient(const char *server_ip, static inline int socketClient(const char *server_ip,
const short server_port, const int timeout, const uint16_t server_port, const int timeout,
const int flags, int *err_no) const int flags, int *err_no)
{ {
return socketClient2(AF_INET, server_ip, server_port, return socketClient2(AF_INET, server_ip, server_port,
@ -498,7 +498,7 @@ static inline int socketClient(const char *server_ip,
* return: >= 0 server socket, < 0 fail * return: >= 0 server socket, < 0 fail
*/ */
static inline int socketClientIPv6(const char *server_ip, static inline int socketClientIPv6(const char *server_ip,
const short server_port, const int timeout, const uint16_t server_port, const int timeout,
const int flags, int *err_no) const int flags, int *err_no)
{ {
return socketClient2(AF_INET6, server_ip, server_port, return socketClient2(AF_INET6, server_ip, server_port,
@ -611,7 +611,7 @@ int getifconfigs(FastIFConfig *if_configs, const int max_count, int *count);
* convert: the convert struct for IPv4 and IPv6 compatibility * convert: the convert struct for IPv4 and IPv6 compatibility
* return: error no, 0 success, != 0 fail * return: error no, 0 success, != 0 fail
*/ */
int setsockaddrbyip(const char *ip, const short port, sockaddr_convert_t *convert); int setsockaddrbyip(const char *ip, const uint16_t port, sockaddr_convert_t *convert);
static inline bool is_ipv6_addr(const char *ip) static inline bool is_ipv6_addr(const char *ip)
{ {