~ubuntu-branches/ubuntu/trusty/libgii/trusty

« back to all changes in this revision

Viewing changes to filter/tcp/filter.c

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar
  • Date: 2006-10-17 19:36:15 UTC
  • mfrom: (3.1.3 edgy)
  • Revision ID: james.westby@ubuntu.com-20061017193615-6civk5a1i4n1kyb0
Tags: 1:1.0.1-3
Fixed "ggtick is missing". Closes: #388682.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: filter.c,v 1.4.2.1 2003/11/13 22:32:05 cegger Exp $
 
1
/* $Id: filter.c,v 1.15 2005/08/04 16:36:37 soyt Exp $
2
2
******************************************************************************
3
3
 
4
4
   Filter-tcp: Repeat events to a TCP-socket
26
26
*/
27
27
 
28
28
#include "config.h"
 
29
#include <ggi/gg.h>
 
30
#include <ggi/internal/gg_replace.h>
29
31
#include <ggi/internal/gii-dl.h>
30
32
#include <ggi/internal/gii_debug.h>
31
33
#include "libtcp.h"
33
35
#include <stdlib.h>
34
36
#include <string.h>
35
37
 
 
38
#ifdef HAVE_STRINGS_H
 
39
#include <strings.h>
 
40
#endif
 
41
 
36
42
#ifdef HAVE_UNISTD_H
37
43
#include <unistd.h>
38
44
#endif
46
52
        fd_set fds;
47
53
        int cnt;
48
54
 
49
 
        GIIDPRINT_EVENTS("GII_tcp_handler(%p) called (fd: %d)\n",
50
 
                         inp, priv->fd);
 
55
        DPRINT_EVENTS("GII_tcp_handler(%p) called (fd: %d)\n",
 
56
                      inp, priv->fd);
51
57
 
52
58
        if (!priv->state) return 0;
53
59
 
54
60
        FD_ZERO(&fds);
55
61
        if (priv->state == GIITCP_LISTEN) {
56
 
                FD_SET(priv->listenfd, &fds);
 
62
                FD_SET((unsigned)(priv->listenfd), &fds);
57
63
                if (select(priv->listenfd + 1, &fds, NULL, NULL, &tv) <= 0) {
58
64
                        return 0;
59
65
                }
60
66
                if (_gii_tcp_accept(priv) == 0) {
61
67
                        fprintf(stderr, "filter-tcp: accepted connection\n");
62
68
                } else {
63
 
                        GIIDPRINT_MISC("GII_tcp_handler: failed to accept connection\n");
 
69
                        DPRINT_MISC("GII_tcp_handler: failed to accept connection\n");
64
70
                }
65
71
                return 0;
66
72
        }
67
73
 
68
 
        FD_SET(priv->fd, &fds);
 
74
        FD_SET((unsigned)(priv->fd), &fds);
69
75
        if (select(priv->fd + 1, NULL, &fds, NULL, &tv) <= 0) {
70
 
                GIIDPRINT_EVENTS("filter-tcp: unable to write event\n");
 
76
                DPRINT_EVENTS("filter-tcp: unable to write event\n");
71
77
                return 0;
72
78
        }
73
79
 
79
85
        }
80
86
 
81
87
        cnt = write(priv->fd, &ev, ev.any.size);
82
 
        if (cnt != ev.any.size) {
 
88
 
 
89
        /* Note, casting cnt to unsigned is wrong here, since
 
90
         * write() can return negative value.
 
91
         */
 
92
        if (cnt != (signed)(ev.any.size)) {
83
93
                if (cnt >= 0) {
84
94
                        fprintf(stderr,
85
 
                                "filter-tcp: only wrote %d of %d bytes\n",
 
95
                                "filter-tcp: only wrote %d of %u bytes\n",
86
96
                                cnt, ev.any.size);
87
97
                        return 0;
88
98
                }
107
117
{
108
118
        gii_tcp_priv *priv = inp->priv;
109
119
 
110
 
        GIIDPRINT_LIBS("GII_tcp_close(%p) called\n", inp);
 
120
        DPRINT_LIBS("GII_tcp_close(%p) called\n", inp);
111
121
 
112
122
        if (priv->fd != -1) _gii_tcp_close(priv->fd);
113
123
        if (priv->listenfd != -1) _gii_tcp_close(priv->listenfd);
114
124
        if (priv->lock) ggLockDestroy(priv->lock);
115
125
        free(priv);
116
126
 
117
 
        GIIDPRINT_LIBS("GII_tcp_close done\n");
 
127
        DPRINT_LIBS("GII_tcp_close done\n");
118
128
 
119
129
        return 0;
120
130
}
121
131
 
122
132
 
123
133
#define MAX_HLEN  256
124
 
int GIIdlinit(gii_input *inp, const char *args, void *argptr)
 
134
EXPORTFUNC int GIIdl_filter_tcp(gii_input *inp, const char *args, void *argptr);
 
135
 
 
136
int GIIdl_filter_tcp(gii_input *inp, const char *args, void *argptr)
125
137
{
126
138
        char host[MAX_HLEN];
127
139
        const char *portstr;
128
 
        int hlen, port, err;
 
140
        size_t hlen;
 
141
        int port, err;
129
142
        gii_tcp_priv *priv;
130
 
 
131
 
        GIIDPRINT_LIBS("filter-tcp init(%p, \"%s\") called\n", inp,
132
 
                       args ? args : "");
 
143
        
 
144
        DPRINT_LIBS("filter-tcp init(%p, \"%s\") called\n", inp,
 
145
                    args ? args : "");
133
146
 
134
147
        if (!args || *args == '\0') return GGI_EARGREQ;
135
148
 
169
182
 
170
183
        inp->GIIhandler   = GII_tcp_handler;
171
184
        inp->GIIclose     = GII_tcp_close;
172
 
 
173
 
        GIIDPRINT_LIBS("filter-tcp fully up\n");
174
 
 
 
185
        
 
186
        DPRINT_LIBS("filter-tcp fully up\n");
 
187
        
175
188
        return 0;
176
189
}