1 /* w32-glib-io.c - W32 Glib I/O functions
2 Copyright (C) 2000 Werner Koch (dd9jn)
3 Copyright (C) 2001, 2002, 2004, 2005 g10 Code GmbH
5 This file is part of GPGME.
7 GPGME is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as
9 published by the Free Software Foundation; either version 2.1 of
10 the License, or (at your option) any later version.
12 GPGME is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
33 #include <sys/types.h>
45 #define O_BINARY _O_BINARY
52 /* This file is an ugly hack to get GPGME working with glib on Windows
53 targets. On Windows, you can not select() on file descriptors.
54 The only way to check if there is something to read is to read
55 something. This means that GPGME can not let glib check for data
56 without letting glib also handle the data on Windows targets.
58 The ugly consequence is that we need to work on GIOChannels in
59 GPGME, creating a glib dependency. Also, we need to export an
60 interface for the application to get at GPGME's GIOChannel. There
61 is no good way to abstract all this with callbacks, because the
62 whole thing is also interconnected with the creation of pipes and
65 The following rule applies only to this I/O backend:
67 * ALL operations must use the user defined event loop. GPGME can
68 not anymore provide its own event loop. This is mostly a sanity
69 requirement: Although we have in theory all information we need to
70 make the GPGME W32 code for select still work, it would be a big
71 complication and require changes throughout GPGME.
73 Eventually, we probably have to bite the bullet and make some
74 really nice callback interfaces to let the user control all this at
75 a per-context level. */
84 /* If this is not -1, then it's a libc file descriptor. */
86 /* If fd is -1, this is the Windows socket handle. */
90 /* The boolean PRIMARY is true if this file descriptor caused the
91 allocation of CHAN. Only then should CHAN be destroyed when this
92 FD is closed. This, together with the fact that dup'ed file
93 descriptors are closed before the file descriptors from which
94 they are dup'ed are closed, ensures that CHAN is always valid,
95 and shared among all file descriptors refering to the same
98 The logic behind this is that there is only one reason for us to
99 dup file descriptors anyway: to allow simpler book-keeping of
100 file descriptors shared between GPGME and libassuan, which both
101 want to close something. Using the same channel for these
102 duplicates works just fine (and in fact, using different channels
103 does not work because the W32 backend in glib does not support
104 that: One would end up with several competing reader/writer
107 } giochannel_table[MAX_SLAFD];
111 find_channel (int fd)
113 if (fd < 0 || fd >= MAX_SLAFD || !giochannel_table[fd].used)
116 return giochannel_table[fd].chan;
120 /* Returns the FD or -1 on resource limit. */
122 new_dummy_channel_from_fd (int cfd)
126 for (idx = 0; idx < MAX_SLAFD; idx++)
127 if (! giochannel_table[idx].used)
130 if (idx == MAX_SLAFD)
136 giochannel_table[idx].used = 1;
137 giochannel_table[idx].chan = NULL;
138 giochannel_table[idx].fd = cfd;
139 giochannel_table[idx].socket = INVALID_SOCKET;
140 giochannel_table[idx].primary = 1;
146 /* Returns the FD or -1 on resource limit. */
148 new_channel_from_fd (int cfd)
152 for (idx = 0; idx < MAX_SLAFD; idx++)
153 if (! giochannel_table[idx].used)
156 if (idx == MAX_SLAFD)
162 giochannel_table[idx].used = 1;
163 giochannel_table[idx].chan = g_io_channel_win32_new_fd (cfd);
164 giochannel_table[idx].fd = cfd;
165 giochannel_table[idx].socket = INVALID_SOCKET;
166 giochannel_table[idx].primary = 1;
168 g_io_channel_set_encoding (giochannel_table[idx].chan, NULL, NULL);
169 g_io_channel_set_buffered (giochannel_table[idx].chan, FALSE);
175 /* Returns the FD or -1 on resource limit. */
177 new_channel_from_socket (int sock)
181 for (idx = 0; idx < MAX_SLAFD; idx++)
182 if (! giochannel_table[idx].used)
185 if (idx == MAX_SLAFD)
191 giochannel_table[idx].used = 1;
192 giochannel_table[idx].chan = g_io_channel_win32_new_socket (sock);
193 giochannel_table[idx].fd = -1;
194 giochannel_table[idx].socket = sock;
195 giochannel_table[idx].primary = 1;
197 g_io_channel_set_encoding (giochannel_table[idx].chan, NULL, NULL);
198 g_io_channel_set_buffered (giochannel_table[idx].chan, FALSE);
204 /* Compatibility interface. Obsolete. */
206 gpgme_get_giochannel (int fd)
208 return find_channel (fd);
212 /* Look up the giochannel for "file descriptor" FD. */
214 gpgme_get_fdptr (int fd)
216 return find_channel (fd);
220 /* Write the printable version of FD to the buffer BUF of length
221 BUFLEN. The printable version is the representation on the command
222 line that the child process expects. */
224 _gpgme_io_fd2str (char *buf, int buflen, int fd)
228 TRACE_BEG1 (DEBUG_SYSIO, "_gpgme_io_fd2str", fd, "fd=%d", fd);
229 if (giochannel_table[fd].fd != -1)
230 hndl = (HANDLE) _get_osfhandle (giochannel_table[fd].fd);
232 hndl = (HANDLE) giochannel_table[fd].socket;
234 TRACE_SUC1 ("syshd=%p", hndl);
236 return snprintf (buf, buflen, "%d", (int) hndl);
241 _gpgme_io_subsystem_init (void)
248 _gpgme_close_notify_handler_t handler;
250 } notify_table[MAX_SLAFD];
254 _gpgme_io_read (int fd, void *buffer, size_t count)
260 TRACE_BEG2 (DEBUG_SYSIO, "_gpgme_io_read", fd,
261 "buffer=%p, count=%u", buffer, count);
263 chan = find_channel (fd);
266 TRACE_LOG ("no channel registered");
268 return TRACE_SYSRES (-1);
270 TRACE_LOG1 ("channel %p", chan);
274 status = g_io_channel_read_chars (chan, (gchar *) buffer,
275 count, &nread, &err);
278 TRACE_LOG2 ("status %i, err %s", status, err->message);
283 if (status == G_IO_STATUS_EOF)
285 else if (status == G_IO_STATUS_AGAIN)
288 saved_errno = EAGAIN;
290 else if (status != G_IO_STATUS_NORMAL)
292 TRACE_LOG1 ("status %d", status);
297 if (nread != 0 && nread != -1)
298 TRACE_LOGBUF (buffer, nread);
301 return TRACE_SYSRES (nread);
306 _gpgme_io_write (int fd, const void *buffer, size_t count)
314 TRACE_BEG2 (DEBUG_SYSIO, "_gpgme_io_write", fd,
315 "buffer=%p, count=%u", buffer, count);
316 TRACE_LOGBUF (buffer, count);
318 chan = find_channel (fd);
321 TRACE_LOG ("fd %d: no channel registered");
326 status = g_io_channel_write_chars (chan, (gchar *) buffer, count,
330 TRACE_LOG1 ("write error: %s", err->message);
334 if (status == G_IO_STATUS_AGAIN)
337 saved_errno = EAGAIN;
339 else if (status != G_IO_STATUS_NORMAL)
346 return TRACE_SYSRES (nwritten);
351 _gpgme_io_pipe (int filedes[2], int inherit_idx)
355 TRACE_BEG2 (DEBUG_SYSIO, "_gpgme_io_pipe", filedes,
356 "inherit_idx=%i (GPGME uses it for %s)",
357 inherit_idx, inherit_idx ? "reading" : "writing");
359 #define PIPEBUF_SIZE 4096
360 if (_pipe (fds, PIPEBUF_SIZE, O_NOINHERIT | O_BINARY) == -1)
361 return TRACE_SYSRES (-1);
363 /* Make one end inheritable. */
364 if (inherit_idx == 0)
368 new_read = _dup (fds[0]);
375 return TRACE_SYSRES (-1);
378 else if (inherit_idx == 1)
382 new_write = _dup (fds[1]);
389 return TRACE_SYSRES (-1);
393 /* For _gpgme_io_close. */
394 filedes[inherit_idx] = new_dummy_channel_from_fd (fds[inherit_idx]);
395 if (filedes[inherit_idx] < 0)
397 int saved_errno = errno;
402 return TRACE_SYSRES (-1);
405 /* Now we have a pipe with the correct end inheritable. The other end
406 should have a giochannel. */
407 filedes[1 - inherit_idx] = new_channel_from_fd (fds[1 - inherit_idx]);
408 if (filedes[1 - inherit_idx] < 0)
410 int saved_errno = errno;
412 _gpgme_io_close (fds[inherit_idx]);
413 _close (fds[1 - inherit_idx]);
415 return TRACE_SYSRES (-1);
418 return TRACE_SUC5 ("read=0x%x/%p, write=0x%x/%p, channel=%p",
420 (HANDLE) _get_osfhandle (giochannel_table[filedes[0]].fd),
422 (HANDLE) _get_osfhandle (giochannel_table[filedes[1]].fd),
423 giochannel_table[1 - inherit_idx].chan);
428 _gpgme_io_close (int fd)
430 TRACE_BEG (DEBUG_SYSIO, "_gpgme_io_close", fd);
432 if (fd < 0 || fd >= MAX_SLAFD)
435 return TRACE_SYSRES (-1);
438 assert (giochannel_table[fd].used);
440 /* First call the notify handler. */
441 if (notify_table[fd].handler)
443 notify_table[fd].handler (fd, notify_table[fd].value);
444 notify_table[fd].handler = NULL;
445 notify_table[fd].value = NULL;
448 /* Then do the close. */
449 if (giochannel_table[fd].chan)
451 if (giochannel_table[fd].primary)
452 g_io_channel_shutdown (giochannel_table[fd].chan, 1, NULL);
454 g_io_channel_unref (giochannel_table[fd].chan);
458 /* Dummy entry, just close. */
459 assert (giochannel_table[fd].fd != -1);
460 _close (giochannel_table[fd].fd);
463 giochannel_table[fd].used = 0;
464 giochannel_table[fd].fd = -1;
465 giochannel_table[fd].socket = INVALID_SOCKET;
466 giochannel_table[fd].chan = NULL;
467 giochannel_table[fd].primary = 0;
475 _gpgme_io_set_close_notify (int fd, _gpgme_close_notify_handler_t handler,
478 TRACE_BEG2 (DEBUG_SYSIO, "_gpgme_io_set_close_notify", fd,
479 "close_handler=%p/%p", handler, value);
483 if (fd < 0 || fd >= (int) DIM (notify_table))
486 return TRACE_SYSRES (-1);
488 notify_table[fd].handler = handler;
489 notify_table[fd].value = value;
490 return TRACE_SYSRES (0);
495 _gpgme_io_set_nonblocking (int fd)
500 TRACE_BEG (DEBUG_SYSIO, "_gpgme_io_set_nonblocking", fd);
502 chan = find_channel (fd);
506 return TRACE_SYSRES (-1);
509 status = g_io_channel_set_flags (chan,
510 g_io_channel_get_flags (chan) |
511 G_IO_FLAG_NONBLOCK, NULL);
513 if (status != G_IO_STATUS_NORMAL)
516 /* glib 1.9.2 does not implement set_flags and returns an
519 return TRACE_SYSRES (-1);
521 TRACE_LOG1 ("g_io_channel_set_flags failed: status=%d (ignored)",
526 return TRACE_SYSRES (0);
531 build_commandline (char **argv)
538 /* We have to quote some things because under Windows the program
539 parses the commandline and does some unquoting. We enclose the
540 whole argument in double-quotes, and escape literal double-quotes
541 as well as backslashes with a backslash. We end up with a
542 trailing space at the end of the line, but that is harmless. */
543 for (i = 0; argv[i]; i++)
546 /* The leading double-quote. */
550 /* An extra one for each literal that must be escaped. */
551 if (*p == '\\' || *p == '"')
556 /* The trailing double-quote and the delimiter. */
559 /* And a trailing zero. */
562 buf = p = malloc (n);
565 for (i = 0; argv[i]; i++)
567 char *argvp = argv[i];
572 if (*argvp == '\\' || *argvp == '"')
586 _gpgme_io_spawn (const char *path, char * const argv[], unsigned int flags,
587 struct spawn_fd_item_s *fd_list,
588 void (*atfork) (void *opaque, int reserved),
589 void *atforkvalue, pid_t *r_pid)
591 SECURITY_ATTRIBUTES sec_attr;
592 PROCESS_INFORMATION pi =
594 NULL, /* returns process handle */
595 0, /* returns primary thread handle */
600 int cr_flags = (CREATE_DEFAULT_ERROR_MODE
601 | GetPriorityClass (GetCurrentProcess ()));
610 TRACE_BEG1 (DEBUG_SYSIO, "_gpgme_io_spawn", path,
615 TRACE_LOG2 ("argv[%2i] = %s", i, argv[i]);
619 /* We do not inherit any handles by default, and just insert those
620 handles we want the child to have afterwards. But some handle
621 values occur on the command line, and we need to move
622 stdin/out/err to the right location. So we use a wrapper program
623 which gets the information from a temporary file. */
624 if (_gpgme_mkstemp (&tmp_fd, &tmp_name) < 0)
626 TRACE_LOG1 ("_gpgme_mkstemp failed: %s", strerror (errno));
627 return TRACE_SYSRES (-1);
629 TRACE_LOG1 ("tmp_name = %s", tmp_name);
631 args = calloc (2 + i + 1, sizeof (*args));
632 args[0] = (char *) _gpgme_get_w32spawn_path ();
635 memcpy (&args[3], &argv[1], i * sizeof (*args));
637 memset (&sec_attr, 0, sizeof sec_attr);
638 sec_attr.nLength = sizeof sec_attr;
639 sec_attr.bInheritHandle = FALSE;
641 arg_string = build_commandline (args);
646 DeleteFile (tmp_name);
647 return TRACE_SYSRES (-1);
650 memset (&si, 0, sizeof si);
652 si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
653 si.wShowWindow = debug_me ? SW_SHOW : SW_HIDE;
654 si.hStdInput = INVALID_HANDLE_VALUE;
655 si.hStdOutput = INVALID_HANDLE_VALUE;
656 si.hStdError = INVALID_HANDLE_VALUE;
658 cr_flags |= CREATE_SUSPENDED;
659 cr_flags |= DETACHED_PROCESS;
660 if (!CreateProcessA (_gpgme_get_w32spawn_path (),
662 &sec_attr, /* process security attributes */
663 &sec_attr, /* thread security attributes */
664 FALSE, /* inherit handles */
665 cr_flags, /* creation flags */
666 NULL, /* environment */
667 NULL, /* use current drive/directory */
668 &si, /* startup information */
669 &pi)) /* returns process information */
671 TRACE_LOG1 ("CreateProcess failed: ec=%d", (int) GetLastError ());
674 DeleteFile (tmp_name);
676 /* FIXME: Should translate the error code. */
678 return TRACE_SYSRES (-1);
683 if (flags & IOSPAWN_FLAG_ALLOW_SET_FG)
684 _gpgme_allow_set_foreground_window ((pid_t)pi.dwProcessId);
686 /* Insert the inherited handles. */
687 for (i = 0; fd_list[i].fd != -1; i++)
691 /* Make it inheritable for the wrapper process. */
692 if (!DuplicateHandle (GetCurrentProcess(),
693 _get_osfhandle (giochannel_table[fd_list[i].fd].fd),
694 pi.hProcess, &hd, 0, TRUE, DUPLICATE_SAME_ACCESS))
696 TRACE_LOG1 ("DuplicateHandle failed: ec=%d", (int) GetLastError ());
697 TerminateProcess (pi.hProcess, 0);
698 /* Just in case TerminateProcess didn't work, let the
699 process fail on its own. */
700 ResumeThread (pi.hThread);
701 CloseHandle (pi.hThread);
702 CloseHandle (pi.hProcess);
705 DeleteFile (tmp_name);
707 /* FIXME: Should translate the error code. */
709 return TRACE_SYSRES (-1);
711 /* Return the child name of this handle. */
712 fd_list[i].peer_name = (int) hd;
715 /* Write the handle translation information to the temporary
718 /* Hold roughly MAX_TRANS quadruplets of 64 bit numbers in hex
719 notation: "0xFEDCBA9876543210" with an extra white space after
720 every quadruplet. 10*(19*4 + 1) - 1 = 769. This plans ahead
721 for a time when a HANDLE is 64 bit. */
722 #define BUFFER_MAX 800
723 char line[BUFFER_MAX + 1];
728 if ((flags & IOSPAWN_FLAG_ALLOW_SET_FG))
729 strcpy (line, "~1 \n");
732 for (i = 0; fd_list[i].fd != -1; i++)
734 /* Strip the newline. */
735 len = strlen (line) - 1;
737 /* Format is: Local name, stdin/stdout/stderr, peer name, argv idx. */
738 snprintf (&line[len], BUFFER_MAX - len, "0x%x %d 0x%x %d \n",
739 fd_list[i].fd, fd_list[i].dup_to,
740 fd_list[i].peer_name, fd_list[i].arg_loc);
741 /* Rather safe than sorry. */
742 line[BUFFER_MAX - 1] = '\n';
743 line[BUFFER_MAX] = '\0';
749 res = write (tmp_fd, &line[written], len - written);
753 while (res > 0 || (res < 0 && errno == EAGAIN));
756 /* The temporary file is deleted by the gpgme-w32spawn process
759 TRACE_LOG4 ("CreateProcess ready: hProcess=%p, hThread=%p, "
760 "dwProcessID=%d, dwThreadId=%d",
761 pi.hProcess, pi.hThread,
762 (int) pi.dwProcessId, (int) pi.dwThreadId);
765 *r_pid = (pid_t)pi.dwProcessId;
767 if (ResumeThread (pi.hThread) < 0)
768 TRACE_LOG1 ("ResumeThread failed: ec=%d", (int) GetLastError ());
770 if (!CloseHandle (pi.hThread))
771 TRACE_LOG1 ("CloseHandle of thread failed: ec=%d",
772 (int) GetLastError ());
774 TRACE_LOG1 ("process=%p", pi.hProcess);
776 /* We don't need to wait for the process. */
777 if (!CloseHandle (pi.hProcess))
778 TRACE_LOG1 ("CloseHandle of process failed: ec=%d",
779 (int) GetLastError ());
781 if (! (flags & IOSPAWN_FLAG_NOCLOSE))
783 for (i = 0; fd_list[i].fd != -1; i++)
784 _gpgme_io_close (fd_list[i].fd);
787 for (i = 0; fd_list[i].fd != -1; i++)
788 if (fd_list[i].dup_to == -1)
789 TRACE_LOG3 ("fd[%i] = 0x%x -> 0x%x", i, fd_list[i].fd,
790 fd_list[i].peer_name);
792 TRACE_LOG4 ("fd[%i] = 0x%x -> 0x%x (std%s)", i, fd_list[i].fd,
793 fd_list[i].peer_name, (fd_list[i].dup_to == 0) ? "in" :
794 ((fd_list[i].dup_to == 1) ? "out" : "err"));
796 return TRACE_SYSRES (0);
800 /* Select on the list of fds. Returns: -1 = error, 0 = timeout or
801 nothing to select, > 0 = number of signaled fds. */
803 _gpgme_io_select (struct io_select_fd_s *fds, size_t nfds, int nonblock)
813 /* Use a 1s timeout. */
815 void *dbg_help = NULL;
816 TRACE_BEG2 (DEBUG_SYSIO, "_gpgme_io_select", fds,
817 "nfds=%u, nonblock=%u", nfds, nonblock);
822 pollfds = calloc (nfds, sizeof *pollfds);
825 pollfds_map = calloc (nfds, sizeof *pollfds_map);
833 TRACE_SEQ (dbg_help, "select on [ ");
835 for (i = 0; i < nfds; i++)
837 GIOChannel *chan = NULL;
842 if ((fds[i].for_read || fds[i].for_write)
843 && !(chan = find_channel (fds[i].fd)))
845 TRACE_ADD1 (dbg_help, "[BAD0x%x ", fds[i].fd);
846 TRACE_END (dbg_help, "]");
847 assert (!"see log file");
849 else if (fds[i].for_read )
852 g_io_channel_win32_make_pollfd (chan, G_IO_IN, pollfds + npollfds);
853 pollfds_map[npollfds] = i;
854 TRACE_ADD2 (dbg_help, "r0x%x<%d> ", fds[i].fd, pollfds[npollfds].fd);
858 else if (fds[i].for_write)
861 g_io_channel_win32_make_pollfd (chan, G_IO_OUT, pollfds + npollfds);
862 pollfds_map[npollfds] = i;
863 TRACE_ADD2 (dbg_help, "w0x%x<%d> ", fds[i].fd, pollfds[npollfds].fd);
869 TRACE_END (dbg_help, "]");
877 count = g_io_channel_win32_poll (pollfds, npollfds, timeout);
880 int saved_errno = errno;
885 TRACE_SEQ (dbg_help, "select OK [ ");
886 if (TRACE_ENABLED (dbg_help))
888 for (i = 0; i < npollfds; i++)
890 if ((pollfds[i].revents & G_IO_IN))
891 TRACE_ADD1 (dbg_help, "r0x%x ", fds[pollfds_map[i]].fd);
892 if ((pollfds[i].revents & G_IO_OUT))
893 TRACE_ADD1 (dbg_help, "w0x%x ", fds[pollfds_map[i]].fd);
895 TRACE_END (dbg_help, "]");
898 /* COUNT is used to stop the lop as soon as possible. */
899 for (n = count, i = 0; i < npollfds && n; i++)
902 assert (j >= 0 && j < nfds);
905 else if (fds[j].for_read)
907 if ((pollfds[i].revents & G_IO_IN))
913 else if (fds[j].for_write)
915 if ((pollfds[i].revents & G_IO_OUT))
926 return TRACE_SYSRES (count);
931 _gpgme_io_dup (int fd)
936 TRACE_BEG (DEBUG_SYSIO, "_gpgme_io_dup", fd);
938 if (fd < 0 || fd >= MAX_SLAFD || !giochannel_table[fd].used)
941 return TRACE_SYSRES (-1);
944 for (newfd = 0; newfd < MAX_SLAFD; newfd++)
945 if (! giochannel_table[newfd].used)
947 if (newfd == MAX_SLAFD)
950 return TRACE_SYSRES (-1);
953 chan = giochannel_table[fd].chan;
954 g_io_channel_ref (chan);
955 giochannel_table[newfd].used = 1;
956 giochannel_table[newfd].chan = chan;
957 giochannel_table[newfd].fd = -1;
958 giochannel_table[newfd].socket = INVALID_SOCKET;
959 giochannel_table[newfd].primary = 0;
961 return TRACE_SYSRES (newfd);
977 case ERROR_BROKEN_PIPE:
979 case WSANOTINITIALISED:
988 _gpgme_io_socket (int domain, int type, int proto)
993 TRACE_BEG2 (DEBUG_SYSIO, "_gpgme_io_socket", domain,
994 "type=%i, protp=%i", type, proto);
996 res = socket (domain, type, proto);
997 if (res == INVALID_SOCKET)
999 errno = wsa2errno (WSAGetLastError ());
1000 return TRACE_SYSRES (-1);
1003 fd = new_channel_from_socket (res);
1006 int saved_errno = errno;
1008 errno = saved_errno;
1009 return TRACE_SYSRES (-1);
1012 TRACE_SUC2 ("fd=%i, socket=0x%x", fd, res);
1019 _gpgme_io_connect (int fd, struct sockaddr *addr, int addrlen)
1028 TRACE_BEG2 (DEBUG_SYSIO, "_gpgme_io_connect", fd,
1029 "addr=%p, addrlen=%i", addr, addrlen);
1031 chan = find_channel (fd);
1035 return TRACE_SYSRES (-1);
1038 flags = g_io_channel_get_flags (chan);
1039 if (flags & G_IO_FLAG_NONBLOCK)
1041 status = g_io_channel_set_flags (chan, flags & ~G_IO_FLAG_NONBLOCK, &err);
1044 TRACE_LOG1 ("setting flags error: %s", err->message);
1048 if (status != G_IO_STATUS_NORMAL)
1051 return TRACE_SYSRES (-1);
1055 sockfd = giochannel_table[fd].socket;
1056 if (sockfd == INVALID_SOCKET)
1059 return TRACE_SYSRES (-1);
1062 TRACE_LOG1 ("connect sockfd=0x%x", sockfd);
1063 res = connect (sockfd, addr, addrlen);
1065 /* FIXME: Error ignored here. */
1066 if (! (flags & G_IO_FLAG_NONBLOCK))
1067 g_io_channel_set_flags (chan, flags, NULL);
1071 TRACE_LOG2 ("connect failed: %i %i", res, WSAGetLastError ());
1073 errno = wsa2errno (WSAGetLastError ());
1074 return TRACE_SYSRES (-1);
1077 return TRACE_SUC ();