listen_fds: use sblist
This commit is contained in:
parent
a5890b621b
commit
7d33fc8e8a
16
src/child.c
16
src/child.c
@ -37,7 +37,7 @@
|
|||||||
#include "mypoll.h"
|
#include "mypoll.h"
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
static vector_t listen_fds;
|
static sblist* listen_fds;
|
||||||
|
|
||||||
struct client {
|
struct client {
|
||||||
union sockaddr_union addr;
|
union sockaddr_union addr;
|
||||||
@ -82,7 +82,7 @@ void child_main_loop (void)
|
|||||||
union sockaddr_union cliaddr_storage;
|
union sockaddr_union cliaddr_storage;
|
||||||
struct sockaddr *cliaddr = (void*) &cliaddr_storage;
|
struct sockaddr *cliaddr = (void*) &cliaddr_storage;
|
||||||
socklen_t clilen = sizeof(cliaddr_storage);
|
socklen_t clilen = sizeof(cliaddr_storage);
|
||||||
int nfds = vector_length(listen_fds);
|
int nfds = sblist_getsize(listen_fds);
|
||||||
pollfd_struct *fds = safecalloc(nfds, sizeof *fds);
|
pollfd_struct *fds = safecalloc(nfds, sizeof *fds);
|
||||||
ssize_t i;
|
ssize_t i;
|
||||||
int ret, listenfd, was_full = 0;
|
int ret, listenfd, was_full = 0;
|
||||||
@ -92,7 +92,7 @@ void child_main_loop (void)
|
|||||||
childs = sblist_new(sizeof (struct child*), config->maxclients);
|
childs = sblist_new(sizeof (struct child*), config->maxclients);
|
||||||
|
|
||||||
for (i = 0; i < nfds; i++) {
|
for (i = 0; i < nfds; i++) {
|
||||||
int *fd = (int *) vector_getentry(listen_fds, i, NULL);
|
int *fd = sblist_get(listen_fds, i);
|
||||||
fds[i].fd = *fd;
|
fds[i].fd = *fd;
|
||||||
fds[i].events |= MYPOLL_READ;
|
fds[i].events |= MYPOLL_READ;
|
||||||
}
|
}
|
||||||
@ -259,7 +259,7 @@ int child_listening_sockets(vector_t listen_addrs, uint16_t port)
|
|||||||
assert (port > 0);
|
assert (port > 0);
|
||||||
|
|
||||||
if (listen_fds == NULL) {
|
if (listen_fds == NULL) {
|
||||||
listen_fds = vector_create();
|
listen_fds = sblist_new(sizeof(int), 16);
|
||||||
if (listen_fds == NULL) {
|
if (listen_fds == NULL) {
|
||||||
log_message (LOG_ERR, "Could not create the list "
|
log_message (LOG_ERR, "Could not create the list "
|
||||||
"of listening fds");
|
"of listening fds");
|
||||||
@ -299,14 +299,14 @@ int child_listening_sockets(vector_t listen_addrs, uint16_t port)
|
|||||||
|
|
||||||
void child_close_sock (void)
|
void child_close_sock (void)
|
||||||
{
|
{
|
||||||
ssize_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i < vector_length(listen_fds); i++) {
|
for (i = 0; i < sblist_getsize(listen_fds); i++) {
|
||||||
int *fd = (int *) vector_getentry(listen_fds, i, NULL);
|
int *fd = sblist_get(listen_fds, i);
|
||||||
close (*fd);
|
close (*fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector_delete(listen_fds);
|
sblist_free(listen_fds);
|
||||||
|
|
||||||
listen_fds = NULL;
|
listen_fds = NULL;
|
||||||
}
|
}
|
||||||
|
@ -277,7 +277,7 @@ static int listen_on_one_socket(struct addrinfo *ad)
|
|||||||
* Upon success, the listen-fds are added to the listen_fds list
|
* Upon success, the listen-fds are added to the listen_fds list
|
||||||
* and 0 is returned. Upon error, -1 is returned.
|
* and 0 is returned. Upon error, -1 is returned.
|
||||||
*/
|
*/
|
||||||
int listen_sock (const char *addr, uint16_t port, vector_t listen_fds)
|
int listen_sock (const char *addr, uint16_t port, sblist* listen_fds)
|
||||||
{
|
{
|
||||||
struct addrinfo hints, *result, *rp;
|
struct addrinfo hints, *result, *rp;
|
||||||
char portstr[6];
|
char portstr[6];
|
||||||
@ -315,7 +315,7 @@ int listen_sock (const char *addr, uint16_t port, vector_t listen_fds)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector_append (listen_fds, &listenfd, sizeof(int));
|
sblist_add (listen_fds, &listenfd);
|
||||||
|
|
||||||
/* success */
|
/* success */
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
#define MAXLINE (1024 * 4)
|
#define MAXLINE (1024 * 4)
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "vector.h"
|
#include "sblist.h"
|
||||||
|
|
||||||
union sockaddr_union {
|
union sockaddr_union {
|
||||||
struct sockaddr_in v4;
|
struct sockaddr_in v4;
|
||||||
@ -37,7 +37,7 @@ union sockaddr_union {
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern int opensock (const char *host, int port, const char *bind_to);
|
extern int opensock (const char *host, int port, const char *bind_to);
|
||||||
extern int listen_sock (const char *addr, uint16_t port, vector_t listen_fds);
|
extern int listen_sock (const char *addr, uint16_t port, sblist* listen_fds);
|
||||||
|
|
||||||
extern int socket_nonblocking (int sock);
|
extern int socket_nonblocking (int sock);
|
||||||
extern int socket_blocking (int sock);
|
extern int socket_blocking (int sock);
|
||||||
|
Loading…
Reference in New Issue
Block a user