Simplify network socket creation code
The socket creation code in mysql_backend.c wasn't MySQL specific and it could be used for all non-blocking network connections. Thus, it makes sense to move it to a common file where other protocol modules can use it. The address resolution code now uses `getaddrinfo` to resolve all addresses instead of manually handling wildcard hosts. This allows the same code to be used for all addresses.
This commit is contained in:
@ -44,10 +44,10 @@ void utils_end();
|
||||
* The configuration is passed as string in the `address|port` format.
|
||||
*
|
||||
* @param config The bind address and port separated by a '|'
|
||||
* @param addr The sockaddr_in6 in which the data is written
|
||||
* @return 1 on success, 0 on failure
|
||||
* @param addr The struct sockaddr_storage in which the data is written
|
||||
* @return True on success, false on failure
|
||||
*/
|
||||
int parse_bindconfig(const char *, struct sockaddr_in6 *, int *);
|
||||
bool parse_bindconfig(const char *config, struct sockaddr_storage *addr);
|
||||
|
||||
|
||||
/**
|
||||
@ -55,9 +55,11 @@ int parse_bindconfig(const char *, struct sockaddr_in6 *, int *);
|
||||
*
|
||||
* @param dest Pointer to a struct sockaddr_storage where the configuration is stored
|
||||
* @param host The target host for which the socket is created
|
||||
* @param port The target port on the host
|
||||
*
|
||||
* @return The opened socket or -1 on failure
|
||||
*/int create_network_socket(struct sockaddr_storage *, char *);
|
||||
*/
|
||||
int open_network_socket(struct sockaddr_storage *dest, char *host, uint16_t port);
|
||||
|
||||
int setnonblocking(int fd);
|
||||
char *gw_strend(register const char *s);
|
||||
|
Reference in New Issue
Block a user