mirror of
https://github.com/moparisthebest/sslh
synced 2024-11-24 01:52:24 -05:00
defered -> deferred
This commit is contained in:
parent
d7bbec0dc7
commit
e4fb8b8496
@ -14,7 +14,7 @@ v1.15: 27JUL2013
|
|||||||
would happen.
|
would happen.
|
||||||
|
|
||||||
Fixed bug in sslh-select: if socket dropped while
|
Fixed bug in sslh-select: if socket dropped while
|
||||||
defered_data was present, sslh-select would crash.
|
deferred_data was present, sslh-select would crash.
|
||||||
|
|
||||||
Increased FD_SETSIZE for Cygwin, as the default 64
|
Increased FD_SETSIZE for Cygwin, as the default 64
|
||||||
is too low for even moderate load.
|
is too low for even moderate load.
|
||||||
|
34
common.c
34
common.c
@ -164,17 +164,17 @@ int defer_write(struct queue *q, void* data, int data_size)
|
|||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
if (verbose)
|
if (verbose)
|
||||||
fprintf(stderr, "**** writing defered on fd %d\n", q->fd);
|
fprintf(stderr, "**** writing deferred on fd %d\n", q->fd);
|
||||||
|
|
||||||
p = realloc(q->defered_data, q->defered_data_size + data_size);
|
p = realloc(q->deferred_data, q->deferred_data_size + data_size);
|
||||||
if (!p) {
|
if (!p) {
|
||||||
perror("realloc");
|
perror("realloc");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
q->defered_data = q->begin_defered_data = p;
|
q->deferred_data = q->begin_deferred_data = p;
|
||||||
p += q->defered_data_size;
|
p += q->deferred_data_size;
|
||||||
q->defered_data_size += data_size;
|
q->deferred_data_size += data_size;
|
||||||
memcpy(p, data, data_size);
|
memcpy(p, data, data_size);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -184,27 +184,27 @@ int defer_write(struct queue *q, void* data, int data_size)
|
|||||||
* Upon success, the number of bytes written is returned.
|
* Upon success, the number of bytes written is returned.
|
||||||
* Upon failure, -1 returned (e.g. connexion closed)
|
* Upon failure, -1 returned (e.g. connexion closed)
|
||||||
* */
|
* */
|
||||||
int flush_defered(struct queue *q)
|
int flush_deferred(struct queue *q)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
fprintf(stderr, "flushing defered data to fd %d\n", q->fd);
|
fprintf(stderr, "flushing deferred data to fd %d\n", q->fd);
|
||||||
|
|
||||||
n = write(q->fd, q->defered_data, q->defered_data_size);
|
n = write(q->fd, q->deferred_data, q->deferred_data_size);
|
||||||
if (n == -1)
|
if (n == -1)
|
||||||
return n;
|
return n;
|
||||||
|
|
||||||
if (n == q->defered_data_size) {
|
if (n == q->deferred_data_size) {
|
||||||
/* All has been written -- release the memory */
|
/* All has been written -- release the memory */
|
||||||
free(q->begin_defered_data);
|
free(q->begin_deferred_data);
|
||||||
q->begin_defered_data = NULL;
|
q->begin_deferred_data = NULL;
|
||||||
q->defered_data = NULL;
|
q->deferred_data = NULL;
|
||||||
q->defered_data_size = 0;
|
q->deferred_data_size = 0;
|
||||||
} else {
|
} else {
|
||||||
/* There is data left */
|
/* There is data left */
|
||||||
q->defered_data += n;
|
q->deferred_data += n;
|
||||||
q->defered_data_size -= n;
|
q->deferred_data_size -= n;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
@ -222,8 +222,8 @@ void init_cnx(struct connection *cnx)
|
|||||||
void dump_connection(struct connection *cnx)
|
void dump_connection(struct connection *cnx)
|
||||||
{
|
{
|
||||||
printf("state: %d\n", cnx->state);
|
printf("state: %d\n", cnx->state);
|
||||||
printf("fd %d, %d defered\n", cnx->q[0].fd, cnx->q[0].defered_data_size);
|
printf("fd %d, %d deferred\n", cnx->q[0].fd, cnx->q[0].deferred_data_size);
|
||||||
printf("fd %d, %d defered\n", cnx->q[1].fd, cnx->q[1].defered_data_size);
|
printf("fd %d, %d deferred\n", cnx->q[1].fd, cnx->q[1].deferred_data_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
10
common.h
10
common.h
@ -58,12 +58,12 @@ enum connection_state {
|
|||||||
#define PROT_SHIFT 1000 /* protocol options will be 1000, 1001, etc */
|
#define PROT_SHIFT 1000 /* protocol options will be 1000, 1001, etc */
|
||||||
|
|
||||||
/* A 'queue' is composed of a file descriptor (which can be read from or
|
/* A 'queue' is composed of a file descriptor (which can be read from or
|
||||||
* written to), and a queue for defered write data */
|
* written to), and a queue for deferred write data */
|
||||||
struct queue {
|
struct queue {
|
||||||
int fd;
|
int fd;
|
||||||
void *begin_defered_data;
|
void *begin_deferred_data;
|
||||||
void *defered_data;
|
void *deferred_data;
|
||||||
int defered_data_size;
|
int deferred_data_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct connection {
|
struct connection {
|
||||||
@ -101,7 +101,7 @@ int resolve_split_name(struct addrinfo **out, const char* hostname, const char*
|
|||||||
int start_listen_sockets(int *sockfd[], struct addrinfo *addr_list);
|
int start_listen_sockets(int *sockfd[], struct addrinfo *addr_list);
|
||||||
|
|
||||||
int defer_write(struct queue *q, void* data, int data_size);
|
int defer_write(struct queue *q, void* data, int data_size);
|
||||||
int flush_defered(struct queue *q);
|
int flush_deferred(struct queue *q);
|
||||||
|
|
||||||
extern int probing_timeout, verbose, inetd, foreground,
|
extern int probing_timeout, verbose, inetd, foreground,
|
||||||
background, transparent, numeric;
|
background, transparent, numeric;
|
||||||
|
4
probe.c
4
probe.c
@ -234,7 +234,7 @@ static int regex_probe(const char *p, int len, struct proto *proto)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Read the beginning of data coming from the client connection and check if
|
* Read the beginning of data coming from the client connection and check if
|
||||||
* it's a known protocol. Then leave the data on the defered
|
* it's a known protocol. Then leave the data on the deferred
|
||||||
* write buffer of the connection and returns a pointer to the protocol
|
* write buffer of the connection and returns a pointer to the protocol
|
||||||
* structure
|
* structure
|
||||||
*/
|
*/
|
||||||
@ -260,7 +260,7 @@ int probe_client_protocol(struct connection *cnx)
|
|||||||
if (verbose) fprintf(stderr, "probing for %s\n", p->description);
|
if (verbose) fprintf(stderr, "probing for %s\n", p->description);
|
||||||
|
|
||||||
cnx->proto = p;
|
cnx->proto = p;
|
||||||
res = p->probe(cnx->q[1].defered_data, cnx->q[1].defered_data_size, p);
|
res = p->probe(cnx->q[1].deferred_data, cnx->q[1].deferred_data_size, p);
|
||||||
}
|
}
|
||||||
if (res != PROBE_NEXT)
|
if (res != PROBE_NEXT)
|
||||||
return res;
|
return res;
|
||||||
|
2
probe.h
2
probe.h
@ -45,7 +45,7 @@ void set_protocol_list(struct proto*);
|
|||||||
/* probe_client_protocol
|
/* probe_client_protocol
|
||||||
*
|
*
|
||||||
* Read the beginning of data coming from the client connection and check if
|
* Read the beginning of data coming from the client connection and check if
|
||||||
* it's a known protocol. Then leave the data on the defered
|
* it's a known protocol. Then leave the data on the deferred
|
||||||
* write buffer of the connection and returns a pointer to the protocol
|
* write buffer of the connection and returns a pointer to the protocol
|
||||||
* structure
|
* structure
|
||||||
*/
|
*/
|
||||||
|
@ -111,7 +111,7 @@ void start_shoveler(int in_socket)
|
|||||||
|
|
||||||
log_connection(&cnx);
|
log_connection(&cnx);
|
||||||
|
|
||||||
flush_defered(&cnx.q[1]);
|
flush_deferred(&cnx.q[1]);
|
||||||
|
|
||||||
shovel(&cnx);
|
shovel(&cnx);
|
||||||
|
|
||||||
|
@ -64,8 +64,8 @@ int tidy_connection(struct connection *cnx, fd_set *fds, fd_set *fds2)
|
|||||||
close(cnx->q[i].fd);
|
close(cnx->q[i].fd);
|
||||||
FD_CLR(cnx->q[i].fd, fds);
|
FD_CLR(cnx->q[i].fd, fds);
|
||||||
FD_CLR(cnx->q[i].fd, fds2);
|
FD_CLR(cnx->q[i].fd, fds2);
|
||||||
if (cnx->q[i].defered_data)
|
if (cnx->q[i].deferred_data)
|
||||||
free(cnx->q[i].defered_data);
|
free(cnx->q[i].deferred_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
init_cnx(cnx);
|
init_cnx(cnx);
|
||||||
@ -137,8 +137,8 @@ int connect_queue(struct connection *cnx, fd_set *fds_r, fd_set *fds_w)
|
|||||||
if ((q->fd != -1) && fd_is_in_range(q->fd)) {
|
if ((q->fd != -1) && fd_is_in_range(q->fd)) {
|
||||||
log_connection(cnx);
|
log_connection(cnx);
|
||||||
set_nonblock(q->fd);
|
set_nonblock(q->fd);
|
||||||
flush_defered(q);
|
flush_deferred(q);
|
||||||
if (q->defered_data) {
|
if (q->deferred_data) {
|
||||||
FD_SET(q->fd, fds_w);
|
FD_SET(q->fd, fds_w);
|
||||||
} else {
|
} else {
|
||||||
FD_SET(q->fd, fds_r);
|
FD_SET(q->fd, fds_r);
|
||||||
@ -192,9 +192,9 @@ int is_fd_active(int fd, fd_set* set)
|
|||||||
* - When a file descriptor goes off, process it: read from it, write the data
|
* - When a file descriptor goes off, process it: read from it, write the data
|
||||||
* to its corresponding pair.
|
* to its corresponding pair.
|
||||||
* - When a file descriptor blocks when writing, remove the read fd from fds_r,
|
* - When a file descriptor blocks when writing, remove the read fd from fds_r,
|
||||||
* move the data to a defered buffer, and add the write fd to fds_w. Defered
|
* move the data to a deferred buffer, and add the write fd to fds_w. Defered
|
||||||
* buffer is allocated dynamically.
|
* buffer is allocated dynamically.
|
||||||
* - When we can write to a file descriptor that has defered data, we try to
|
* - When we can write to a file descriptor that has deferred data, we try to
|
||||||
* write as much as we can. Once all data is written, remove the fd from fds_w
|
* write as much as we can. Once all data is written, remove the fd from fds_w
|
||||||
* and add its corresponding pair to fds_r, free the buffer.
|
* and add its corresponding pair to fds_r, free the buffer.
|
||||||
*
|
*
|
||||||
@ -265,16 +265,16 @@ void main_loop(int listen_sockets[], int num_addr_listen)
|
|||||||
if (cnx[i].q[0].fd != -1) {
|
if (cnx[i].q[0].fd != -1) {
|
||||||
for (j = 0; j < 2; j++) {
|
for (j = 0; j < 2; j++) {
|
||||||
if (is_fd_active(cnx[i].q[j].fd, &writefds)) {
|
if (is_fd_active(cnx[i].q[j].fd, &writefds)) {
|
||||||
res = flush_defered(&cnx[i].q[j]);
|
res = flush_deferred(&cnx[i].q[j]);
|
||||||
if ((res == -1) && ((errno == EPIPE) || (errno == ECONNRESET))) {
|
if ((res == -1) && ((errno == EPIPE) || (errno == ECONNRESET))) {
|
||||||
if (cnx[i].state == ST_PROBING) num_probing--;
|
if (cnx[i].state == ST_PROBING) num_probing--;
|
||||||
tidy_connection(&cnx[i], &fds_r, &fds_w);
|
tidy_connection(&cnx[i], &fds_r, &fds_w);
|
||||||
if (verbose)
|
if (verbose)
|
||||||
fprintf(stderr, "closed slot %d\n", i);
|
fprintf(stderr, "closed slot %d\n", i);
|
||||||
} else {
|
} else {
|
||||||
/* If no defered data is left, stop monitoring the fd
|
/* If no deferred data is left, stop monitoring the fd
|
||||||
* for write, and restart monitoring the other one for reads*/
|
* for write, and restart monitoring the other one for reads*/
|
||||||
if (!cnx[i].q[j].defered_data_size) {
|
if (!cnx[i].q[j].deferred_data_size) {
|
||||||
FD_CLR(cnx[i].q[j].fd, &fds_w);
|
FD_CLR(cnx[i].q[j].fd, &fds_w);
|
||||||
FD_SET(cnx[i].q[1-j].fd, &fds_r);
|
FD_SET(cnx[i].q[1-j].fd, &fds_r);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user