File: socket_listen.c

package info (click to toggle)
libowfat 0.34-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,288 kB
  • sloc: ansic: 20,181; makefile: 16
file content (33 lines) | stat: -rw-r--r-- 743 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <sys/types.h>
#ifdef __MINGW32__
#include "io_internal.h"
#include <mswsock.h>
#else
#include <sys/socket.h>
#endif
#include "socket.h"
#include "windoze.h"

int socket_listen(int s,unsigned int backlog) {
#ifdef __MINGW32__
  io_entry* e;
  int r = listen(s, backlog);
  if (r==-1) return winsock2errno(-1);
  e=array_get(&io_fds,sizeof(io_entry),s);
  if (e && e->inuse) {
    e->listened=1;
    if (e->wantread) {
      /* queue a non-blocking accept */
      DWORD received;
      e->next_accept=socket(AF_INET,SOCK_STREAM,0);
      if (e->next_accept!=-1) {
        AcceptEx(s,e->next_accept,e->inbuf,0,200,200,&received,&e->or);
	e->acceptqueued=1;
      }
    }
  }
  return r;
#else
  return listen(s, (int)backlog);
#endif
}