> Date: Sat, 23 Jun 2007 16:04:17 +0200
> From: vtorri@univ-evry.fr
> To: mingw-users@lists.sourceforge.net
> Subject: Re: [Mingw-users] main loop (ala glib) and windows message loop
>
>
>
> On Sat, 23 Jun 2007, Vincent Torri wrote:
>
> > I've tried to use it without success. Maybe I don't understand well 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 fake_socket_pair ?
>

read() and write() do not work for sockets on Windows. Use recv() and send().

Luke

 
> Vincent Torri
>
>
>
> #include <stdio.h>
> #include <unistd.h>
> #include <errno.h>
> #include <winsock2.h>
>
> #define FDREAD 0
> #define FDWRITE 1
>
> int
> main (int argc, char *argv[])
> {
> int sockets[2];
> WSADATA version_data;
> int *i;
> void *buf[1];
> int ret;
> fd_set rfds;
>
> FD_ZERO(&rfds);
>
> WSAStartup(MAKEWORD(2, 2), &version_data);
>
> if (fake_socketpair(sockets) < 0)
> {
> printf ("error\n");
> return -1;
> }
> FD_SET(sockets[FDREAD], &rfds);
> i = (int *)malloc(sizeof (int));
> *i = 1;
> buf[0] = i;
> write(sockets[FDWRITE], buf, sizeof(buf));
> printf (" * select : select %d %d\n", sockets[0], sockets[1]);
> ret = select(sockets[FDREAD] + 1, &rfds, NULL, NULL, NULL);
> printf (" * select : ret %d\n", ret);
> if (ret < 0) return -1;
> if (ret > 0)
> {
> int len;
> int *j = 0;
>
> printf ("bon \n");
> while ((len = read(sockets[FDREAD], buf, sizeof(buf))) > 0)
> {
> if (len == sizeof(buf))
> {
> j = 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 limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> MinGW-users mailing list
> MinGW-users@lists.sourceforge.net
>
> You may change your MinGW Account Options or unsubscribe at:
> https://lists.sourceforge.net/lists/listinfo/mingw-users