|
From: Luke D. <cod...@ho...> - 2007-06-23 15:24:28
|
> Date: Sat, 23 Jun 2007 16:04:17 +0200> From: vt...@un...> To: min=
gw-...@li...> Subject: Re: [Mingw-users] main loop (ala g=
lib) and windows message loop> > > > On Sat, 23 Jun 2007, Vincent Torri wro=
te:> > > I've tried to use it without success. Maybe I don't understand wel=
l ho> > to use it.> >> > Do you have a small example of use of fake_socket_=
pair() with the select()> > function, please ?> > I've written a test code =
below and select() also blocks.> > Is there something wrong in it, or in fa=
ke_socket_pair ?>=20
read() and write() do not work for sockets on Windows. Use recv() and send(=
).
Luke
=20
> Vincent Torri> > > > #include <stdio.h>> #include <unistd.h>> #include <e=
rrno.h>> #include <winsock2.h>> > #define FDREAD 0> #define FDWRITE 1> > in=
t> main (int argc, char *argv[])> {> int sockets[2];> WSADATA version_data;=
> int *i;> void *buf[1];> int ret;> fd_set rfds;> > FD_ZERO(&rfds);> > WSAS=
tartup(MAKEWORD(2, 2), &version_data);> > if (fake_socketpair(sockets) < 0)=
> {> printf ("error\n");> return -1;> }> FD_SET(sockets[FDREAD], &rfds);> i=
=3D (int *)malloc(sizeof (int));> *i =3D 1;> buf[0] =3D i;> write(sockets[=
FDWRITE], buf, sizeof(buf));> printf (" * select : select %d %d\n", sockets=
[0], sockets[1]);> ret =3D select(sockets[FDREAD] + 1, &rfds, NULL, NULL, N=
ULL);> printf (" * select : ret %d\n", ret);> if (ret < 0) return -1;> if (=
ret > 0)> {> int len;> int *j =3D 0;> > printf ("bon \n");> while ((len =3D=
read(sockets[FDREAD], buf, sizeof(buf))) > 0)> {> if (len =3D=3D sizeof(bu=
f))> {> j =3D buf[0];> printf ("reussite : %d\n", *j);> }> }> }> > return 0=
;> }> > -------------------------------------------------------------------=
------> This SF.net email is sponsored by DB2 Express> Download DB2 Express=
C - the FREE version of DB2 express and take> control of your XML. No limi=
ts. Just data. Click to get it now.> http://sourceforge.net/powerbar/db2/> =
_______________________________________________> MinGW-users mailing list> =
Min...@li...> > You may change your MinGW Account Opti=
ons or unsubscribe at:> https://lists.sourceforge.net/lists/listinfo/mingw-=
users=
|