Close the other end of the connection too.
[cascardo/rnetproxy.git] / nethook.c
1 /*
2 ** Copyright (C) 2006 Thadeu Lima de Souza Cascardo <cascardo@minaslivre.org>
3 **  
4 ** This program is free software; you can redistribute it and/or modify
5 ** it under the terms of the GNU General Public License as published by
6 ** the Free Software Foundation; either version 2 of the License, or
7 ** (at your option) any later version.
8 **  
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 ** GNU General Public License for more details.
13 **  
14 ** You should have received a copy of the GNU General Public License
15 ** along with this program; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 **  
18 */
19
20 #include "nethook.h"
21
22 void
23 nethook_event (HCConn* conn, HCEvent event, gpointer data)
24 {
25   char buffer[4096];
26   int r;
27   net_hook_t* hook;
28   hook = (net_hook_t*) data;
29   switch (event)
30     {
31     case HC_EVENT_CONNECT:
32       hook->connect (hook);
33       break;
34     case HC_EVENT_READ:
35       while ((r = hc_conn_read (conn, buffer, sizeof (buffer))) > 0)
36         hook->read (hook, buffer, r);
37       break;
38     case HC_EVENT_CLOSE:
39       hook->close (hook);
40       break;
41     default:
42       g_warning ("Received an unexpected client event.");
43       break;
44     }
45 }