- Timestamp:
- 2015-10-26T03:42:15Z (9 years ago)
- Branches:
- master
- Children:
- 0db6618
- Parents:
- f710673
- git-author:
- dequis <dx@…> (25-10-15 04:06:22)
- git-committer:
- dequis <dx@…> (26-10-15 03:42:15)
- Location:
- lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/proxy.c
rf710673 r4e365ce 51 51 #endif 52 52 53 static GHashTable *phb_hash = NULL; 54 53 55 struct PHB { 54 56 b_event_handler func, proxy_func; … … 67 69 static gboolean phb_free(struct PHB *phb, gboolean success) 68 70 { 71 g_hash_table_remove(phb_hash, &phb->fd); 72 69 73 if (!success) { 70 74 if (phb->fd > 0) { … … 100 104 dup2(new_fd, source); 101 105 closesocket(new_fd); 106 phb->fd = source; 102 107 phb->inpa = b_input_add(source, B_EV_IO_WRITE, proxy_connected, phb); 103 108 return FALSE; … … 523 528 struct PHB *phb; 524 529 proxy_connect_func fun; 530 int fd; 531 532 if (!phb_hash) { 533 phb_hash = g_hash_table_new(g_int_hash, g_int_equal); 534 } 525 535 526 536 if (!host || port <= 0 || !func || strlen(host) > 128) { … … 538 548 } 539 549 540 return fun(host, port, phb); 541 } 550 fd = fun(host, port, phb); 551 552 if (fd != -1) { 553 g_hash_table_insert(phb_hash, &phb->fd, phb); 554 } 555 556 return fd; 557 } 558 559 void proxy_disconnect(int fd) 560 { 561 struct PHB *phb = g_hash_table_lookup(phb_hash, &fd); 562 563 if (!phb) { 564 /* not in the early part of the connection - just close the fd */ 565 closesocket(fd); 566 return; 567 } 568 569 if (phb->inpa) { 570 b_event_remove(phb->inpa); 571 phb->inpa = 0; 572 } 573 574 /* avoid calling the callback, which might result in double-free */ 575 phb->func = NULL; 576 577 /* close and free */ 578 phb_free(phb, FALSE); 579 } -
lib/proxy.h
rf710673 r4e365ce 49 49 50 50 G_MODULE_EXPORT int proxy_connect(const char *host, int port, b_event_handler func, gpointer data); 51 G_MODULE_EXPORT void proxy_disconnect(int fd); 51 52 52 53 #endif /* _PROXY_H_ */
Note: See TracChangeset
for help on using the changeset viewer.