Changeset fa271b8 in code
- Timestamp:
- Mar 4, 2014, 10:34:15 AM (11 years ago)
- Branches:
- master
- Children:
- b4049f9
- Parents:
- a202ff1
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
icb.h
ra202ff1 rfa271b8 16 16 17 17 #include <sys/queue.h> 18 #include <sys/tree.h> 18 19 19 20 #define ICB_MSGSIZE 256 … … 66 67 67 68 struct icb_session { 69 uint64_t id; 68 70 char nick[ICB_MAXNICKLEN]; 69 71 char client[ICB_MAXNICKLEN]; … … 71 73 char buffer[ICB_MSGSIZE+1]; 72 74 struct event ev; 73 LIST_ENTRY(icb_session) entry;74 75 struct bufferevent *bev; 75 76 struct icb_group *group; … … 87 88 #define ICB_SF_NOBEEP 0x10 88 89 #define ICB_SF_NOBEEP2 0x20 90 91 /* session tree */ 92 RB_ENTRY(icb_session) node; 93 94 /* in-group linkage */ 95 LIST_ENTRY(icb_session) entry; 89 96 }; 90 97 -
icbd.c
ra202ff1 rfa271b8 20 20 #include <sys/socket.h> 21 21 #include <sys/stat.h> 22 #include <sys/tree.h> 22 23 #include <netinet/in_systm.h> 23 24 #include <netinet/in.h> … … 44 45 extern char *__progname; 45 46 47 uint64_t sessionid; 46 48 char modtab[ICB_MTABLEN][ICB_MAXNICKLEN]; 47 49 int modtabcnt; … … 63 65 void icbd_write(struct icb_session *, char *, ssize_t); 64 66 67 static inline int icbd_session_cmp(struct icb_session *, struct icb_session *); 68 69 RB_HEAD(icbd_sessions, icb_session) icbd_sessions; 70 RB_PROTOTYPE(icbd_sessions, icb_session, node, icbd_session_cmp); 71 RB_GENERATE(icbd_sessions, icb_session, node, icbd_session_cmp); 72 65 73 int 66 74 main(int argc, char *argv[]) … … 70 78 int ch, nsocks = 0, save_errno = 0; 71 79 int inet4 = 0, inet6 = 0; 80 81 RB_INIT(&icbd_sessions); 72 82 73 83 /* init group lists before calling icb_addgroup */ … … 234 244 } 235 245 246 static inline int 247 icbd_session_cmp(struct icb_session *a, struct icb_session *b) 248 { 249 if (a->id > b->id) 250 return (1); 251 if (a->id < b->id) 252 return (-1); 253 return (0); 254 } 255 256 inline struct icb_session * 257 icbd_session_lookup(uint64_t sid) 258 { 259 struct icb_session key; 260 261 key.id = sid; 262 return (RB_FIND(icbd_sessions, &icbd_sessions, &key)); 263 } 264 236 265 void 237 266 icbd_accept(int fd, short event __attribute__((__unused__)), … … 270 299 return; 271 300 } 301 302 is->id = sessionid++; 303 RB_INSERT(icbd_sessions, &icbd_sessions, is); 272 304 273 305 /* save host information */ … … 354 386 (void)close(EVBUFFER_FD(is->bev)); 355 387 bufferevent_free(is->bev); 388 RB_REMOVE(icbd_sessions, &icbd_sessions, is); 356 389 free(is); 357 390 } -
icbd.h
ra202ff1 rfa271b8 24 24 25 25 /* icbd.c */ 26 time_t getmonotime(void); 26 inline struct icb_session *icbd_session_lookup(uint64_t); 27 time_t getmonotime(void); 27 28 28 29 /* dns.c */
Note:
See TracChangeset
for help on using the changeset viewer.