Mercurial > pidgin
annotate src/gtkeventloop.c @ 8436:4bb3d8dc717e
[gaim-migrate @ 9166]
" If getaddrinfo() is used, the addrlen and addr returned
through that function are written through the pipe to
the child Gaim processes. getaddrinfo() sets the
addrlen and addr fields through the following
structure, defined in <netdb.h>:
struct addrinfo {
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
size_t ai_addrlen;
char *ai_canonname;
struct sockaddr *ai_addr;
struct addrinfo *ai_next;
};
This is from FreeBSD/amd64 5.2.1-RELEASE. This
structure is defined differently on different systems.
Take, for example, this OpenBSD/i386 3.5-beta system:
struct addrinfo {
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
socklen_t ai_addrlen;
struct sockaddr *ai_addr;
char *ai_canonname;
struct addrinfo *ai_next;
};
After being read, the addrlen and addr of each host is
written through the descriptor:
src/proxy.c:
466 rc =
getaddrinfo(dns_params.hostname, servname, &hints, &res);
...
478 while(res) {
479
write(child_out[1], &(res->ai_addrlen),
sizeof(res->ai_addrlen));
480
write(child_out[1], res->ai_addr, res->ai_addrlen);
481 res =
res->ai_next;
482 }
And later subsequently read:
286 rc=read(req->fd_out,
&addrlen, sizeof(addrlen));
287 if(rc>0 && addrlen > 0) {
288
addr=g_malloc(addrlen);
289
rc=read(req->fd_out, addr, addrlen);
So hence, the type of addrlen that is used in
host_resolved() must match that of the addrlen used in
the addrinfo structure, or they must at least be
guarenteed to be the same size." --jarady
committer: Tailor Script <tailor@pidgin.im>
| author | Luke Schierer <lschiere@pidgin.im> |
|---|---|
| date | Fri, 12 Mar 2004 16:59:22 +0000 |
| parents | ef881489396e |
| children | 9949b752d1ab |
| rev | line source |
|---|---|
| 8273 | 1 /** |
| 2 * @file gtk_eventloop.c Gaim Event Loop API (gtk implementation) | |
| 3 * @ingroup gtkui | |
| 4 * | |
| 5 * gaim | |
| 6 * | |
| 7 * Gaim is the legal property of its developers, whose names are too numerous | |
| 8 * to list here. Please refer to the COPYRIGHT file distributed with this | |
| 9 * source distribution. | |
| 10 * | |
| 11 * This program is free software; you can redistribute it and/or modify | |
| 12 * it under the terms of the GNU General Public License as published by | |
| 13 * the Free Software Foundation; either version 2 of the License, or | |
| 14 * (at your option) any later version. | |
| 15 * | |
| 16 * This program is distributed in the hope that it will be useful, | |
| 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 19 * GNU General Public License for more details. | |
| 20 * | |
| 21 * You should have received a copy of the GNU General Public License | |
| 22 * along with this program; if not, write to the Free Software | |
| 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 24 */ | |
| 25 | |
| 26 #include <glib.h> | |
| 27 #include "gtkeventloop.h" | |
| 28 #include "eventloop.h" | |
| 29 | |
| 30 #define GAIM_GTK_READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR) | |
| 31 #define GAIM_GTK_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL) | |
| 32 | |
| 33 typedef struct _GaimGtkIOClosure { | |
| 34 GaimInputFunction function; | |
| 35 guint result; | |
| 36 gpointer data; | |
| 37 | |
| 38 } GaimGtkIOClosure; | |
| 39 | |
| 40 static void gaim_gtk_io_destroy(gpointer data) | |
| 41 { | |
| 42 g_free(data); | |
| 43 } | |
| 44 | |
| 45 static gboolean gaim_gtk_io_invoke(GIOChannel *source, GIOCondition condition, gpointer data) | |
| 46 { | |
| 47 GaimGtkIOClosure *closure = data; | |
| 48 GaimInputCondition gaim_cond = 0; | |
| 49 | |
| 50 if (condition & GAIM_GTK_READ_COND) | |
| 51 gaim_cond |= GAIM_INPUT_READ; | |
| 52 if (condition & GAIM_GTK_WRITE_COND) | |
| 53 gaim_cond |= GAIM_INPUT_WRITE; | |
| 54 | |
| 55 #if 0 | |
| 56 gaim_debug(GAIM_DEBUG_MISC, "gtk_eventloop", | |
| 57 "CLOSURE: callback for %d, fd is %d\n", | |
| 58 closure->result, g_io_channel_unix_get_fd(source)); | |
| 59 #endif | |
| 60 | |
| 61 closure->function(closure->data, g_io_channel_unix_get_fd(source), gaim_cond); | |
| 62 | |
| 63 return TRUE; | |
| 64 } | |
| 65 | |
|
8280
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
66 static guint gaim_gtk_input_add(gint fd, GaimInputCondition condition, GaimInputFunction function, |
| 8273 | 67 gpointer data) |
| 68 { | |
| 69 GaimGtkIOClosure *closure = g_new0(GaimGtkIOClosure, 1); | |
| 70 GIOChannel *channel; | |
| 71 GIOCondition cond = 0; | |
| 72 | |
| 73 closure->function = function; | |
| 74 closure->data = data; | |
| 75 | |
| 76 if (condition & GAIM_INPUT_READ) | |
| 77 cond |= GAIM_GTK_READ_COND; | |
| 78 if (condition & GAIM_INPUT_WRITE) | |
| 79 cond |= GAIM_GTK_WRITE_COND; | |
| 80 | |
|
8280
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
81 channel = g_io_channel_unix_new(fd); |
| 8273 | 82 closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond, |
| 83 gaim_gtk_io_invoke, closure, gaim_gtk_io_destroy); | |
| 84 | |
| 85 #if 0 | |
| 86 gaim_debug(GAIM_DEBUG_MISC, "gtk_eventloop", | |
| 87 "CLOSURE: adding input watcher %d for fd %d\n", | |
|
8280
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
88 closure->result, fd); |
| 8273 | 89 #endif |
| 90 | |
| 91 g_io_channel_unref(channel); | |
| 92 return closure->result; | |
| 93 } | |
| 94 | |
| 95 static GaimEventLoopUiOps eventloop_ops = | |
| 96 { | |
| 97 g_timeout_add, | |
|
8287
ef881489396e
[gaim-migrate @ 9011]
Christian Hammond <chipx86@chipx86.com>
parents:
8280
diff
changeset
|
98 g_source_remove, |
| 8273 | 99 gaim_gtk_input_add, |
|
8287
ef881489396e
[gaim-migrate @ 9011]
Christian Hammond <chipx86@chipx86.com>
parents:
8280
diff
changeset
|
100 g_source_remove |
| 8273 | 101 }; |
| 102 | |
| 103 GaimEventLoopUiOps * | |
| 104 gaim_gtk_eventloop_get_ui_ops(void) | |
| 105 { | |
| 106 return &eventloop_ops; | |
| 107 } |
