converted listeners to the linked list functions
Этот коммит содержится в:
родитель
08cad8e14c
Коммит
a871f0b214
@ -92,7 +92,7 @@ LIBSSH2_CHANNEL *
|
||||
_libssh2_channel_locate(LIBSSH2_SESSION *session, unsigned long channel_id)
|
||||
{
|
||||
LIBSSH2_CHANNEL *channel;
|
||||
LIBSSH2_LISTENER *listener;
|
||||
LIBSSH2_LISTENER *l;
|
||||
|
||||
for(channel = session->channels.head; channel; channel = channel->next) {
|
||||
if (channel->local.id == channel_id)
|
||||
@ -101,8 +101,9 @@ _libssh2_channel_locate(LIBSSH2_SESSION *session, unsigned long channel_id)
|
||||
|
||||
/* We didn't find the channel in the session, let's then check its
|
||||
listeners... */
|
||||
for(listener = session->listeners; listener; listener = listener->next) {
|
||||
for(channel = listener->queue; channel; channel = channel->next) {
|
||||
for(l = _libssh2_list_first(&session->listeners); l;
|
||||
l = _libssh2_list_next(&l->node)) {
|
||||
for(channel = l->queue; channel; channel = channel->next) {
|
||||
if (channel->local.id == channel_id)
|
||||
return channel;
|
||||
}
|
||||
@ -585,12 +586,8 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host,
|
||||
listener->queue_size = 0;
|
||||
listener->queue_maxsize = queue_maxsize;
|
||||
|
||||
listener->next = session->listeners;
|
||||
listener->prev = NULL;
|
||||
if (session->listeners) {
|
||||
session->listeners->prev = listener;
|
||||
}
|
||||
session->listeners = listener;
|
||||
/* append this to the parent's list of listeners */
|
||||
_libssh2_list_add(&session->listeners, &listener->node);
|
||||
|
||||
if (bound_port) {
|
||||
*bound_port = listener->port;
|
||||
@ -713,14 +710,8 @@ static int channel_forward_cancel(LIBSSH2_LISTENER *listener)
|
||||
}
|
||||
LIBSSH2_FREE(session, listener->host);
|
||||
|
||||
if (listener->next) {
|
||||
listener->next->prev = listener->prev;
|
||||
}
|
||||
if (listener->prev) {
|
||||
listener->prev->next = listener->next;
|
||||
} else {
|
||||
session->listeners = listener->next;
|
||||
}
|
||||
/* remove this entry from the parent's list of listeners */
|
||||
_libssh2_list_remove(&listener->node);
|
||||
|
||||
LIBSSH2_FREE(session, listener);
|
||||
|
||||
|
@ -437,6 +437,8 @@ struct _LIBSSH2_CHANNEL_BRIGADE
|
||||
|
||||
struct _LIBSSH2_LISTENER
|
||||
{
|
||||
struct list_node node; /* linked list header */
|
||||
|
||||
LIBSSH2_SESSION *session;
|
||||
|
||||
char *host;
|
||||
@ -446,8 +448,6 @@ struct _LIBSSH2_LISTENER
|
||||
int queue_size;
|
||||
int queue_maxsize;
|
||||
|
||||
LIBSSH2_LISTENER *prev, *next;
|
||||
|
||||
/* State variables used in libssh2_channel_forward_cancel() */
|
||||
libssh2_nonblocking_states chanFwdCncl_state;
|
||||
unsigned char *chanFwdCncl_data;
|
||||
@ -724,7 +724,7 @@ struct _LIBSSH2_SESSION
|
||||
LIBSSH2_CHANNEL_BRIGADE channels;
|
||||
unsigned long next_channel;
|
||||
|
||||
LIBSSH2_LISTENER *listeners;
|
||||
struct list_head listeners; /* list of LIBSSH2_LISTENER structs */
|
||||
|
||||
/* Actual I/O socket */
|
||||
int socket_fd;
|
||||
|
@ -78,7 +78,7 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data,
|
||||
/* 17 = packet_type(1) + channel(4) + reason(4) + descr(4) + lang(4) */
|
||||
unsigned long packet_len = 17 + (sizeof(FwdNotReq) - 1);
|
||||
unsigned char *p;
|
||||
LIBSSH2_LISTENER *listen = session->listeners;
|
||||
LIBSSH2_LISTENER *listen = _libssh2_list_first(&session->listeners);
|
||||
char failure_code = 1; /* SSH_OPEN_ADMINISTRATIVELY_PROHIBITED */
|
||||
int rc;
|
||||
|
||||
@ -238,7 +238,7 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data,
|
||||
}
|
||||
}
|
||||
|
||||
listen = listen->next;
|
||||
listen = _libssh2_list_next(&listen->node);
|
||||
}
|
||||
|
||||
listen_state->state = libssh2_NB_state_sent;
|
||||
|
@ -734,11 +734,11 @@ session_free(LIBSSH2_SESSION *session)
|
||||
}
|
||||
|
||||
if (session->state == libssh2_NB_state_sent) {
|
||||
while (session->listeners) {
|
||||
rc = libssh2_channel_forward_cancel(session->listeners);
|
||||
if (rc == PACKET_EAGAIN) {
|
||||
LIBSSH2_LISTENER *l;
|
||||
while (l = _libssh2_list_first(&session->listeners)) {
|
||||
rc = libssh2_channel_forward_cancel(l);
|
||||
if (rc == PACKET_EAGAIN)
|
||||
return PACKET_EAGAIN;
|
||||
}
|
||||
}
|
||||
|
||||
session->state = libssh2_NB_state_sent1;
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user