ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.c
(Generate patch)

Comparing libev/ev.c (file contents):
Revision 1.71 by root, Tue Nov 6 13:17:55 2007 UTC vs.
Revision 1.72 by root, Tue Nov 6 16:09:37 2007 UTC

64#include <assert.h> 64#include <assert.h>
65#include <errno.h> 65#include <errno.h>
66#include <sys/types.h> 66#include <sys/types.h>
67#include <time.h> 67#include <time.h>
68 68
69#ifndef PERL
70# include <signal.h> 69#include <signal.h>
71#endif
72 70
73#ifndef WIN32 71#ifndef WIN32
74# include <unistd.h> 72# include <unistd.h>
75# include <sys/time.h> 73# include <sys/time.h>
76# include <sys/wait.h> 74# include <sys/wait.h>
154 152
155#if WIN32 153#if WIN32
156/* note: the comment below could not be substantiated, but what would I care */ 154/* note: the comment below could not be substantiated, but what would I care */
157/* MSDN says this is required to handle SIGFPE */ 155/* MSDN says this is required to handle SIGFPE */
158volatile double SIGFPE_REQ = 0.0f; 156volatile double SIGFPE_REQ = 0.0f;
157
158static int
159ev_socketpair_tcp (int filedes [2])
160{
161 struct sockaddr_in addr = { 0 };
162 int addr_size = sizeof (addr);
163 SOCKET listener;
164 SOCKET sock [2] = { -1, -1 };
165
166 if ((listener = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
167 return -1;
168
169 addr.sin_family = AF_INET;
170 addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
171 addr.sin_port = 0;
172
173 if (bind (listener, (struct sockaddr *)&addr, addr_size))
174 goto fail;
175
176 if (getsockname(listener, (struct sockaddr *)&addr, &addr_size))
177 goto fail;
178
179 if (listen (listener, 1))
180 goto fail;
181
182 if ((sock [0] = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
183 goto fail;
184
185 if (connect (sock[0], (struct sockaddr *)&addr, addr_size))
186 goto fail;
187
188 if ((sock[1] = accept (listener, 0, 0)) < 0)
189 goto fail;
190
191 closesocket (listener);
192
193 filedes [0] = sock [0];
194 filedes [1] = sock [1];
195
196 return 0;
197
198fail:
199 closesocket (listener);
200
201 if (sock [0] != INVALID_SOCKET) closesocket (sock [0]);
202 if (sock [1] != INVALID_SOCKET) closesocket (sock [1]);
203
204 return -1;
205}
206
207# define ev_pipe(filedes) ev_socketpair_tcp (filedes)
208#else
209# define ev_pipe(filedes) pipe (filedes)
159#endif 210#endif
160 211
161/*****************************************************************************/ 212/*****************************************************************************/
162 213
163static void (*syserr_cb)(const char *msg); 214static void (*syserr_cb)(const char *msg);
777 ev_ref (EV_A); 828 ev_ref (EV_A);
778 ev_io_stop (EV_A_ &sigev); 829 ev_io_stop (EV_A_ &sigev);
779 close (sigpipe [0]); 830 close (sigpipe [0]);
780 close (sigpipe [1]); 831 close (sigpipe [1]);
781 832
782 while (pipe (sigpipe)) 833 while (ev_pipe (sigpipe))
783 syserr ("(libev) error creating pipe"); 834 syserr ("(libev) error creating pipe");
784 835
785 siginit (EV_A); 836 siginit (EV_A);
786 } 837 }
787 838
830int 881int
831#endif 882#endif
832ev_default_loop (int methods) 883ev_default_loop (int methods)
833{ 884{
834 if (sigpipe [0] == sigpipe [1]) 885 if (sigpipe [0] == sigpipe [1])
835 if (pipe (sigpipe)) 886 if (ev_pipe (sigpipe))
836 return 0; 887 return 0;
837 888
838 if (!default_loop) 889 if (!default_loop)
839 { 890 {
840#if EV_MULTIPLICITY 891#if EV_MULTIPLICITY

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines