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.
|
||||
|
||||
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
|
||||
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;
|
||||
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) {
|
||||
perror("realloc");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
q->defered_data = q->begin_defered_data = p;
|
||||
p += q->defered_data_size;
|
||||
q->defered_data_size += data_size;
|
||||
q->deferred_data = q->begin_deferred_data = p;
|
||||
p += q->deferred_data_size;
|
||||
q->deferred_data_size += data_size;
|
||||
memcpy(p, data, data_size);
|
||||
|
||||
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 failure, -1 returned (e.g. connexion closed)
|
||||
* */
|
||||
int flush_defered(struct queue *q)
|
||||
int flush_deferred(struct queue *q)
|
||||
{
|
||||
int n;
|
||||
|
||||
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)
|
||||
return n;
|
||||
|
||||
if (n == q->defered_data_size) {
|
||||
if (n == q->deferred_data_size) {
|
||||
/* All has been written -- release the memory */
|
||||
free(q->begin_defered_data);
|
||||
q->begin_defered_data = NULL;
|
||||
q->defered_data = NULL;
|
||||
q->defered_data_size = 0;
|
||||
free(q->begin_deferred_data);
|
||||
q->begin_deferred_data = NULL;
|
||||
q->deferred_data = NULL;
|
||||
q->deferred_data_size = 0;
|
||||
} else {
|
||||
/* There is data left */
|
||||
q->defered_data += n;
|
||||
q->defered_data_size -= n;
|
||||
q->deferred_data += n;
|
||||
q->deferred_data_size -= n;
|
||||
}
|
||||
|
||||
return n;
|
||||
@ -222,8 +222,8 @@ void init_cnx(struct connection *cnx)
|
||||
void dump_connection(struct connection *cnx)
|
||||
{
|
||||
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 defered\n", cnx->q[1].fd, cnx->q[1].defered_data_size);
|
||||
printf("fd %d, %d deferred\n", cnx->q[0].fd, cnx->q[0].deferred_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 */
|
||||
|
||||
/* 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 {
|
||||
int fd;
|
||||
void *begin_defered_data;
|
||||
void *defered_data;
|
||||
int defered_data_size;
|
||||
void *begin_deferred_data;
|
||||
void *deferred_data;
|
||||
int deferred_data_size;
|
||||
};
|
||||
|
||||
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 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,
|
||||
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
|
||||
* 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
|
||||
* structure
|
||||
*/
|
||||
@ -260,7 +260,7 @@ int probe_client_protocol(struct connection *cnx)
|
||||
if (verbose) fprintf(stderr, "probing for %s\n", p->description);
|
||||
|
||||
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)
|
||||
return res;
|
||||
|
2
probe.h
2
probe.h
@ -45,7 +45,7 @@ void set_protocol_list(struct proto*);
|
||||
/* probe_client_protocol
|
||||
*
|
||||
* 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
|
||||
* structure
|
||||
*/
|
||||
|
@ -111,7 +111,7 @@ void start_shoveler(int in_socket)
|
||||
|
||||
log_connection(&cnx);
|
||||
|
||||
flush_defered(&cnx.q[1]);
|
||||
flush_deferred(&cnx.q[1]);
|
||||
|
||||
shovel(&cnx);
|
||||
|
||||
|
@ -64,8 +64,8 @@ int tidy_connection(struct connection *cnx, fd_set *fds, fd_set *fds2)
|
||||
close(cnx->q[i].fd);
|
||||
FD_CLR(cnx->q[i].fd, fds);
|
||||
FD_CLR(cnx->q[i].fd, fds2);
|
||||
if (cnx->q[i].defered_data)
|
||||
free(cnx->q[i].defered_data);
|
||||
if (cnx->q[i].deferred_data)
|
||||
free(cnx->q[i].deferred_data);
|
||||
}
|
||||
}
|
||||
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)) {
|
||||
log_connection(cnx);
|
||||
set_nonblock(q->fd);
|
||||
flush_defered(q);
|
||||
if (q->defered_data) {
|
||||
flush_deferred(q);
|
||||
if (q->deferred_data) {
|
||||
FD_SET(q->fd, fds_w);
|
||||
} else {
|
||||
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
|
||||
* to its corresponding pair.
|
||||
* - 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.
|
||||
* - 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
|
||||
* 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) {
|
||||
for (j = 0; j < 2; j++) {
|
||||
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 (cnx[i].state == ST_PROBING) num_probing--;
|
||||
tidy_connection(&cnx[i], &fds_r, &fds_w);
|
||||
if (verbose)
|
||||
fprintf(stderr, "closed slot %d\n", i);
|
||||
} 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*/
|
||||
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_SET(cnx[i].q[1-j].fd, &fds_r);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user