Browse Source

replace sys/queue with cork_dllist

pull/148/head
Max Lv 10 years ago
parent
commit
6118fefd04
2 changed files with 16 additions and 11 deletions
  1. 22
      src/local.c
  2. 5
      src/local.h

22
src/local.c

@ -54,6 +54,8 @@
#define SET_INTERFACE #define SET_INTERFACE
#endif #endif
#include <libcork/core.h>
#ifdef __MINGW32__ #ifdef __MINGW32__
#include "win32.h" #include "win32.h"
#endif #endif
@ -103,7 +105,7 @@ static void close_and_free_server(EV_P_ struct server *server);
static struct remote * new_remote(int fd, int timeout); static struct remote * new_remote(int fd, int timeout);
static struct server * new_server(int fd, int method); static struct server * new_server(int fd, int method);
static TAILQ_HEAD(connection_head, server) connections;
static struct cork_dllist connections;
#ifndef __MINGW32__ #ifndef __MINGW32__
int setnonblocking(int fd) int setnonblocking(int fd)
@ -180,10 +182,12 @@ int create_and_bind(const char *addr, const char *port)
static void free_connections(struct ev_loop *loop) static void free_connections(struct ev_loop *loop)
{ {
struct server *iter;
while ((iter = TAILQ_FIRST(&connections)) != NULL) {
struct remote *remote = iter->remote;
close_and_free_server(loop, iter);
struct cork_dllist_item *curr;
for (curr = cork_dllist_start(&connections); !cork_dllist_is_end(&connections, curr);
curr = curr->next) {
struct server *server = cork_container_of(curr, struct server, entries);
struct remote *remote = server->remote;
close_and_free_server(loop, server);
close_and_free_remote(loop, remote); close_and_free_remote(loop, remote);
} }
} }
@ -749,14 +753,14 @@ static struct server * new_server(int fd, int method)
server->d_ctx = NULL; server->d_ctx = NULL;
} }
TAILQ_INSERT_HEAD(&connections, server, entries);
cork_dllist_add(&connections, &server->entries);
return server; return server;
} }
static void free_server(struct server *server) static void free_server(struct server *server)
{ {
TAILQ_REMOVE(&connections, server, entries);
cork_dllist_remove(&server->entries);
if (server->remote != NULL) { if (server->remote != NULL) {
server->remote->server = NULL; server->remote->server = NULL;
@ -1109,7 +1113,7 @@ int main(int argc, char **argv)
} }
// Init connections // Init connections
TAILQ_INIT(&connections);
cork_dllist_init(&connections);
// Enter the loop // Enter the loop
ev_run(loop, 0); ev_run(loop, 0);
@ -1223,7 +1227,7 @@ int start_ss_local_server(profile_t profile)
} }
// Init connections // Init connections
TAILQ_INIT(&connections);
cork_dllist_init(&connections);
// Enter the loop // Enter the loop
ev_run(loop, 0); ev_run(loop, 0);

5
src/local.h

@ -23,8 +23,9 @@
#ifndef _LOCAL_H #ifndef _LOCAL_H
#define _LOCAL_H #define _LOCAL_H
#include <sys/queue.h>
#include <ev.h> #include <ev.h>
#include <libcork/ds.h>
#include "encrypt.h" #include "encrypt.h"
#include "jconf.h" #include "jconf.h"
@ -60,7 +61,7 @@ struct server {
struct listen_ctx *listener; struct listen_ctx *listener;
struct remote *remote; struct remote *remote;
TAILQ_ENTRY(server) entries;
struct cork_dllist_item entries;
}; };
struct remote_ctx { struct remote_ctx {

Loading…
Cancel
Save