1997-09-04 06:45:56 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
2011-07-27 07:17:02 -07:00
|
|
|
/* OCaml */
|
1997-09-04 06:45:56 -07:00
|
|
|
/* */
|
2008-07-31 05:09:18 -07:00
|
|
|
/* Contributed by Sylvain Le Gall for Lexifi */
|
1997-09-04 06:45:56 -07:00
|
|
|
/* */
|
2008-07-31 05:09:18 -07:00
|
|
|
/* Copyright 2008 Institut National de Recherche en Informatique et */
|
1999-11-17 10:59:06 -08:00
|
|
|
/* en Automatique. All rights reserved. This file is distributed */
|
2001-12-07 05:41:02 -08:00
|
|
|
/* under the terms of the GNU Library General Public License, with */
|
|
|
|
/* the special exception on linking described in file ../../LICENSE. */
|
1997-09-04 06:45:56 -07:00
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#include <mlvalues.h>
|
|
|
|
#include <alloc.h>
|
|
|
|
#include <memory.h>
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
#include <fail.h>
|
1997-09-04 06:45:56 -07:00
|
|
|
#include <signals.h>
|
2008-07-29 01:31:41 -07:00
|
|
|
#include <winsock2.h>
|
|
|
|
#include <windows.h>
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
#include <stdio.h>
|
1997-09-04 06:45:56 -07:00
|
|
|
#include "unixsupport.h"
|
2008-07-29 01:31:41 -07:00
|
|
|
#include "windbug.h"
|
|
|
|
#include "winworker.h"
|
|
|
|
#include "winlist.h"
|
1997-09-04 06:45:56 -07:00
|
|
|
|
2008-07-29 01:31:41 -07:00
|
|
|
/* This constant define the maximum number of objects that
|
|
|
|
* can be handle by a SELECTDATA.
|
|
|
|
* It takes the following parameters into account:
|
|
|
|
* - limitation on number of objects is mostly due to limitation
|
|
|
|
* a WaitForMultipleObjects
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
* - there is always an event "hStop" to watch
|
2008-07-29 01:31:41 -07:00
|
|
|
*
|
|
|
|
* This lead to pick the following value as the biggest possible
|
|
|
|
* value
|
|
|
|
*/
|
|
|
|
#define MAXIMUM_SELECT_OBJECTS (MAXIMUM_WAIT_OBJECTS - 1)
|
|
|
|
|
|
|
|
/* Manage set of handle */
|
|
|
|
typedef struct _SELECTHANDLESET {
|
|
|
|
LPHANDLE lpHdl;
|
|
|
|
DWORD nMax;
|
|
|
|
DWORD nLast;
|
|
|
|
} SELECTHANDLESET;
|
|
|
|
|
|
|
|
typedef SELECTHANDLESET *LPSELECTHANDLESET;
|
|
|
|
|
|
|
|
void handle_set_init (LPSELECTHANDLESET hds, LPHANDLE lpHdl, DWORD max)
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
hds->lpHdl = lpHdl;
|
|
|
|
hds->nMax = max;
|
|
|
|
hds->nLast = 0;
|
|
|
|
|
|
|
|
/* Set to invalid value every entry of the handle */
|
|
|
|
for (i = 0; i < hds->nMax; i++)
|
|
|
|
{
|
|
|
|
hds->lpHdl[i] = INVALID_HANDLE_VALUE;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void handle_set_add (LPSELECTHANDLESET hds, HANDLE hdl)
|
|
|
|
{
|
|
|
|
LPSELECTHANDLESET res;
|
|
|
|
|
|
|
|
if (hds->nLast < hds->nMax)
|
|
|
|
{
|
|
|
|
hds->lpHdl[hds->nLast] = hdl;
|
|
|
|
hds->nLast++;
|
|
|
|
}
|
|
|
|
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Adding handle %x to set %x", hdl, hds);
|
2008-07-29 01:31:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL handle_set_mem (LPSELECTHANDLESET hds, HANDLE hdl)
|
|
|
|
{
|
|
|
|
BOOL res;
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
res = FALSE;
|
|
|
|
for (i = 0; !res && i < hds->nLast; i++)
|
|
|
|
{
|
|
|
|
res = (hds->lpHdl[i] == hdl);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void handle_set_reset (LPSELECTHANDLESET hds)
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
for (i = 0; i < hds->nMax; i++)
|
|
|
|
{
|
|
|
|
hds->lpHdl[i] = INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
hds->nMax = 0;
|
|
|
|
hds->nLast = 0;
|
|
|
|
hds->lpHdl = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Data structure for handling select */
|
|
|
|
|
|
|
|
typedef enum _SELECTHANDLETYPE {
|
|
|
|
SELECT_HANDLE_NONE = 0,
|
|
|
|
SELECT_HANDLE_DISK,
|
|
|
|
SELECT_HANDLE_CONSOLE,
|
|
|
|
SELECT_HANDLE_PIPE,
|
|
|
|
SELECT_HANDLE_SOCKET,
|
|
|
|
} SELECTHANDLETYPE;
|
|
|
|
|
|
|
|
typedef enum _SELECTMODE {
|
|
|
|
SELECT_MODE_NONE = 0,
|
|
|
|
SELECT_MODE_READ,
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
SELECT_MODE_WRITE,
|
2008-07-29 01:31:41 -07:00
|
|
|
SELECT_MODE_EXCEPT,
|
|
|
|
} SELECTMODE;
|
|
|
|
|
|
|
|
typedef enum _SELECTSTATE {
|
|
|
|
SELECT_STATE_NONE = 0,
|
|
|
|
SELECT_STATE_INITFAILED,
|
|
|
|
SELECT_STATE_ERROR,
|
|
|
|
SELECT_STATE_SIGNALED
|
|
|
|
} SELECTSTATE;
|
|
|
|
|
|
|
|
typedef enum _SELECTTYPE {
|
|
|
|
SELECT_TYPE_NONE = 0,
|
|
|
|
SELECT_TYPE_STATIC, /* Result is known without running anything */
|
|
|
|
SELECT_TYPE_CONSOLE_READ, /* Reading data on console */
|
|
|
|
SELECT_TYPE_PIPE_READ, /* Reading data on pipe */
|
|
|
|
SELECT_TYPE_SOCKET /* Classic select */
|
|
|
|
} SELECTTYPE;
|
|
|
|
|
|
|
|
/* Data structure for results */
|
|
|
|
typedef struct _SELECTRESULT {
|
|
|
|
LIST lst;
|
|
|
|
SELECTMODE EMode;
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
int lpOrigIdx;
|
2008-07-29 01:31:41 -07:00
|
|
|
} SELECTRESULT;
|
|
|
|
|
|
|
|
typedef SELECTRESULT *LPSELECTRESULT;
|
|
|
|
|
|
|
|
/* Data structure for query */
|
|
|
|
typedef struct _SELECTQUERY {
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
LIST lst;
|
|
|
|
SELECTMODE EMode;
|
|
|
|
HANDLE hFileDescr;
|
|
|
|
int lpOrigIdx;
|
|
|
|
unsigned int uFlagsFd; /* Copy of filedescr->flags_fd */
|
2008-07-29 01:31:41 -07:00
|
|
|
} SELECTQUERY;
|
|
|
|
|
|
|
|
typedef SELECTQUERY *LPSELECTQUERY;
|
|
|
|
|
|
|
|
typedef struct _SELECTDATA {
|
|
|
|
LIST lst;
|
|
|
|
SELECTTYPE EType;
|
|
|
|
SELECTRESULT aResults[MAXIMUM_SELECT_OBJECTS];
|
|
|
|
DWORD nResultsCount;
|
|
|
|
/* Data following are dedicated to APC like call, they
|
|
|
|
will be initialized if required.
|
|
|
|
*/
|
|
|
|
WORKERFUNC funcWorker;
|
|
|
|
SELECTQUERY aQueries[MAXIMUM_SELECT_OBJECTS];
|
|
|
|
DWORD nQueriesCount;
|
|
|
|
SELECTSTATE EState;
|
|
|
|
DWORD nError;
|
|
|
|
LPWORKER lpWorker;
|
|
|
|
} SELECTDATA;
|
|
|
|
|
|
|
|
typedef SELECTDATA *LPSELECTDATA;
|
|
|
|
|
|
|
|
/* Get error status if associated condition is false */
|
|
|
|
static BOOL check_error(LPSELECTDATA lpSelectData, BOOL bFailed)
|
|
|
|
{
|
|
|
|
if (bFailed && lpSelectData->nError == 0)
|
|
|
|
{
|
|
|
|
lpSelectData->EState = SELECT_STATE_ERROR;
|
|
|
|
lpSelectData->nError = GetLastError();
|
|
|
|
}
|
|
|
|
return bFailed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create data associated with a select operation */
|
|
|
|
LPSELECTDATA select_data_new (LPSELECTDATA lpSelectData, SELECTTYPE EType)
|
|
|
|
{
|
|
|
|
/* Allocate the data structure */
|
|
|
|
LPSELECTDATA res;
|
|
|
|
DWORD i;
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
|
|
|
|
res = (LPSELECTDATA)caml_stat_alloc(sizeof(SELECTDATA));
|
2008-07-29 01:31:41 -07:00
|
|
|
|
|
|
|
/* Init common data */
|
|
|
|
list_init((LPLIST)res);
|
|
|
|
list_next_set((LPLIST)res, (LPLIST)lpSelectData);
|
|
|
|
res->EType = EType;
|
|
|
|
res->nResultsCount = 0;
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
|
2008-07-29 01:31:41 -07:00
|
|
|
|
|
|
|
/* Data following are dedicated to APC like call, they
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
will be initialized if required. For now they are set to
|
2008-07-29 01:31:41 -07:00
|
|
|
invalid values.
|
|
|
|
*/
|
|
|
|
res->funcWorker = NULL;
|
|
|
|
res->nQueriesCount = 0;
|
|
|
|
res->EState = SELECT_STATE_NONE;
|
|
|
|
res->nError = 0;
|
|
|
|
res->lpWorker = NULL;
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free select data */
|
|
|
|
void select_data_free (LPSELECTDATA lpSelectData)
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Freeing data of %x", lpSelectData);
|
2008-07-29 01:31:41 -07:00
|
|
|
|
|
|
|
/* Free APC related data, if they exists */
|
|
|
|
if (lpSelectData->lpWorker != NULL)
|
|
|
|
{
|
|
|
|
worker_job_finish(lpSelectData->lpWorker);
|
|
|
|
lpSelectData->lpWorker = NULL;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Make sure results/queries cannot be accessed */
|
|
|
|
lpSelectData->nResultsCount = 0;
|
|
|
|
lpSelectData->nQueriesCount = 0;
|
|
|
|
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
caml_stat_free(lpSelectData);
|
2008-07-29 01:31:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add a result to select data, return zero if something goes wrong. */
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DWORD select_data_result_add (LPSELECTDATA lpSelectData, SELECTMODE EMode, int lpOrigIdx)
|
2008-07-29 01:31:41 -07:00
|
|
|
{
|
|
|
|
DWORD res;
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
res = 0;
|
|
|
|
if (lpSelectData->nResultsCount < MAXIMUM_SELECT_OBJECTS)
|
|
|
|
{
|
|
|
|
i = lpSelectData->nResultsCount;
|
|
|
|
lpSelectData->aResults[i].EMode = EMode;
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
lpSelectData->aResults[i].lpOrigIdx = lpOrigIdx;
|
2008-07-29 01:31:41 -07:00
|
|
|
lpSelectData->nResultsCount++;
|
|
|
|
res = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add a query to select data, return zero if something goes wrong */
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DWORD select_data_query_add (LPSELECTDATA lpSelectData,
|
|
|
|
SELECTMODE EMode,
|
|
|
|
HANDLE hFileDescr,
|
|
|
|
int lpOrigIdx,
|
|
|
|
unsigned int uFlagsFd)
|
1997-09-04 06:45:56 -07:00
|
|
|
{
|
2008-07-29 01:31:41 -07:00
|
|
|
DWORD res;
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DWORD i;
|
2008-07-29 01:31:41 -07:00
|
|
|
|
|
|
|
res = 0;
|
|
|
|
if (lpSelectData->nQueriesCount < MAXIMUM_SELECT_OBJECTS)
|
|
|
|
{
|
|
|
|
i = lpSelectData->nQueriesCount;
|
|
|
|
lpSelectData->aQueries[i].EMode = EMode;
|
|
|
|
lpSelectData->aQueries[i].hFileDescr = hFileDescr;
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
lpSelectData->aQueries[i].lpOrigIdx = lpOrigIdx;
|
|
|
|
lpSelectData->aQueries[i].uFlagsFd = uFlagsFd;
|
2008-07-29 01:31:41 -07:00
|
|
|
lpSelectData->nQueriesCount++;
|
|
|
|
res = 1;
|
1997-09-04 06:45:56 -07:00
|
|
|
}
|
2008-07-29 01:31:41 -07:00
|
|
|
|
|
|
|
return res;
|
1997-09-04 06:45:56 -07:00
|
|
|
}
|
|
|
|
|
2008-07-29 01:31:41 -07:00
|
|
|
/* Search for a job that has available query slots and that match provided type.
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
* If none is found, create a new one. Return the corresponding SELECTDATA, and
|
2008-07-29 01:31:41 -07:00
|
|
|
* update provided SELECTDATA head, if required.
|
|
|
|
*/
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
LPSELECTDATA select_data_job_search (LPSELECTDATA *lppSelectData, SELECTTYPE EType)
|
1997-09-04 06:45:56 -07:00
|
|
|
{
|
2008-07-29 01:31:41 -07:00
|
|
|
LPSELECTDATA res;
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
|
2008-07-29 01:31:41 -07:00
|
|
|
res = NULL;
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
|
2008-07-29 01:31:41 -07:00
|
|
|
/* Search for job */
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Searching an available job for type %d", EType);
|
2008-07-29 01:31:41 -07:00
|
|
|
res = *lppSelectData;
|
|
|
|
while (
|
|
|
|
res != NULL
|
|
|
|
&& !(
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
res->EType == EType
|
2008-07-29 01:31:41 -07:00
|
|
|
&& res->nQueriesCount < MAXIMUM_SELECT_OBJECTS
|
|
|
|
)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
res = LIST_NEXT(LPSELECTDATA, res);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No matching job found, create one */
|
|
|
|
if (res == NULL)
|
|
|
|
{
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("No job for type %d found, create one", EType);
|
2008-07-29 01:31:41 -07:00
|
|
|
res = select_data_new(*lppSelectData, EType);
|
|
|
|
*lppSelectData = res;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************/
|
|
|
|
/* Console */
|
|
|
|
/***********************/
|
|
|
|
|
|
|
|
void read_console_poll(HANDLE hStop, void *_data)
|
|
|
|
{
|
|
|
|
HANDLE events[2];
|
|
|
|
INPUT_RECORD record;
|
|
|
|
DWORD waitRes;
|
|
|
|
DWORD n;
|
|
|
|
LPSELECTDATA lpSelectData;
|
|
|
|
LPSELECTQUERY lpQuery;
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
|
|
|
|
DEBUG_PRINT("Waiting for data on console");
|
2008-07-29 01:31:41 -07:00
|
|
|
|
|
|
|
record;
|
|
|
|
waitRes = 0;
|
|
|
|
n = 0;
|
|
|
|
lpSelectData = (LPSELECTDATA)_data;
|
|
|
|
lpQuery = &(lpSelectData->aQueries[0]);
|
|
|
|
|
|
|
|
events[0] = hStop;
|
|
|
|
events[1] = lpQuery->hFileDescr;
|
|
|
|
while (lpSelectData->EState == SELECT_STATE_NONE)
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
{
|
2008-07-29 01:31:41 -07:00
|
|
|
waitRes = WaitForMultipleObjects(2, events, FALSE, INFINITE);
|
|
|
|
if (waitRes == WAIT_OBJECT_0 || check_error(lpSelectData, waitRes == WAIT_FAILED))
|
|
|
|
{
|
|
|
|
/* stop worker event or error */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* console event */
|
|
|
|
if (check_error(lpSelectData, PeekConsoleInput(lpQuery->hFileDescr, &record, 1, &n) == 0))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* check for ASCII keypress only */
|
|
|
|
if (record.EventType == KEY_EVENT &&
|
|
|
|
record.Event.KeyEvent.bKeyDown &&
|
|
|
|
record.Event.KeyEvent.uChar.AsciiChar != 0)
|
|
|
|
{
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
select_data_result_add(lpSelectData, lpQuery->EMode, lpQuery->lpOrigIdx);
|
2008-07-29 01:31:41 -07:00
|
|
|
lpSelectData->EState = SELECT_STATE_SIGNALED;
|
|
|
|
break;
|
|
|
|
}
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
else
|
2008-07-29 01:31:41 -07:00
|
|
|
{
|
|
|
|
/* discard everything else and try again */
|
|
|
|
if (check_error(lpSelectData, ReadConsoleInput(lpQuery->hFileDescr, &record, 1, &n) == 0))
|
|
|
|
{
|
|
|
|
break;
|
1997-09-04 06:45:56 -07:00
|
|
|
}
|
|
|
|
}
|
2008-07-29 01:31:41 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add a function to monitor console input */
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
LPSELECTDATA read_console_poll_add (LPSELECTDATA lpSelectData,
|
|
|
|
SELECTMODE EMode,
|
|
|
|
HANDLE hFileDescr,
|
|
|
|
int lpOrigIdx,
|
|
|
|
unsigned int uFlagsFd)
|
2008-07-29 01:31:41 -07:00
|
|
|
{
|
|
|
|
LPSELECTDATA res;
|
|
|
|
|
|
|
|
res = select_data_new(lpSelectData, SELECT_TYPE_CONSOLE_READ);
|
|
|
|
res->funcWorker = read_console_poll;
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
select_data_query_add(res, SELECT_MODE_READ, hFileDescr, lpOrigIdx, uFlagsFd);
|
2008-07-29 01:31:41 -07:00
|
|
|
|
1997-09-04 06:45:56 -07:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2008-07-29 01:31:41 -07:00
|
|
|
/***********************/
|
|
|
|
/* Pipe */
|
|
|
|
/***********************/
|
|
|
|
|
|
|
|
/* Monitor a pipe for input */
|
|
|
|
void read_pipe_poll (HANDLE hStop, void *_data)
|
|
|
|
{
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DWORD res;
|
2008-07-29 01:31:41 -07:00
|
|
|
DWORD event;
|
|
|
|
DWORD n;
|
|
|
|
LPSELECTQUERY iterQuery;
|
|
|
|
LPSELECTDATA lpSelectData;
|
|
|
|
DWORD i;
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DWORD wait;
|
2008-07-29 01:31:41 -07:00
|
|
|
|
|
|
|
/* Poll pipe */
|
|
|
|
event = 0;
|
|
|
|
n = 0;
|
|
|
|
lpSelectData = (LPSELECTDATA)_data;
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
wait = 1;
|
2008-07-29 01:31:41 -07:00
|
|
|
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Checking data pipe");
|
2008-07-29 01:31:41 -07:00
|
|
|
while (lpSelectData->EState == SELECT_STATE_NONE)
|
|
|
|
{
|
|
|
|
for (i = 0; i < lpSelectData->nQueriesCount; i++)
|
|
|
|
{
|
|
|
|
iterQuery = &(lpSelectData->aQueries[i]);
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
res = PeekNamedPipe(
|
|
|
|
iterQuery->hFileDescr,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
&n,
|
|
|
|
NULL);
|
|
|
|
if (check_error(lpSelectData,
|
|
|
|
(res == 0) &&
|
|
|
|
(GetLastError() != ERROR_BROKEN_PIPE)))
|
2008-07-29 01:31:41 -07:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
if ((n > 0) || (res == 0))
|
2008-07-29 01:31:41 -07:00
|
|
|
{
|
|
|
|
lpSelectData->EState = SELECT_STATE_SIGNALED;
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
select_data_result_add(lpSelectData, iterQuery->EMode, iterQuery->lpOrigIdx);
|
2008-07-29 01:31:41 -07:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Alas, nothing except polling seems to work for pipes.
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
Check the state & stop_worker_event every 10 ms
|
2008-07-29 01:31:41 -07:00
|
|
|
*/
|
|
|
|
if (lpSelectData->EState == SELECT_STATE_NONE)
|
|
|
|
{
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
event = WaitForSingleObject(hStop, wait);
|
|
|
|
|
|
|
|
/* Fast start: begin to wait 1, 2, 4, 8 and then 10 ms.
|
|
|
|
* If we are working with the output of a program there is
|
|
|
|
* a chance that one of the 4 first calls succeed.
|
|
|
|
*/
|
|
|
|
wait = 2 * wait;
|
|
|
|
if (wait > 10)
|
|
|
|
{
|
|
|
|
wait = 10;
|
|
|
|
};
|
2008-07-29 01:31:41 -07:00
|
|
|
if (event == WAIT_OBJECT_0 || check_error(lpSelectData, event == WAIT_FAILED))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Finish checking data on pipe");
|
2008-07-29 01:31:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add a function to monitor pipe input */
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
LPSELECTDATA read_pipe_poll_add (LPSELECTDATA lpSelectData,
|
|
|
|
SELECTMODE EMode,
|
|
|
|
HANDLE hFileDescr,
|
|
|
|
int lpOrigIdx,
|
|
|
|
unsigned int uFlagsFd)
|
2008-07-29 01:31:41 -07:00
|
|
|
{
|
|
|
|
LPSELECTDATA res;
|
|
|
|
LPSELECTDATA hd;
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
|
2008-07-29 01:31:41 -07:00
|
|
|
hd = lpSelectData;
|
|
|
|
/* Polling pipe is a non blocking operation by default. This means that each
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
worker can handle many pipe. We begin to try to find a worker that is
|
2008-07-29 01:31:41 -07:00
|
|
|
polling pipe, but for which there is under the limit of pipe per worker.
|
|
|
|
*/
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Searching an available worker handling pipe");
|
2008-07-29 01:31:41 -07:00
|
|
|
res = select_data_job_search(&hd, SELECT_TYPE_PIPE_READ);
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
|
2008-07-29 01:31:41 -07:00
|
|
|
/* Add a new pipe to poll */
|
|
|
|
res->funcWorker = read_pipe_poll;
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
select_data_query_add(res, EMode, hFileDescr, lpOrigIdx, uFlagsFd);
|
2008-07-29 01:31:41 -07:00
|
|
|
|
|
|
|
return hd;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************/
|
|
|
|
/* Socket */
|
|
|
|
/***********************/
|
|
|
|
|
|
|
|
/* Monitor socket */
|
|
|
|
void socket_poll (HANDLE hStop, void *_data)
|
|
|
|
{
|
|
|
|
LPSELECTDATA lpSelectData;
|
|
|
|
LPSELECTQUERY iterQuery;
|
|
|
|
HANDLE aEvents[MAXIMUM_SELECT_OBJECTS];
|
|
|
|
DWORD nEvents;
|
|
|
|
long maskEvents;
|
|
|
|
DWORD i;
|
|
|
|
u_long iMode;
|
|
|
|
|
|
|
|
lpSelectData = (LPSELECTDATA)_data;
|
|
|
|
|
|
|
|
for (nEvents = 0; nEvents < lpSelectData->nQueriesCount; nEvents++)
|
|
|
|
{
|
|
|
|
iterQuery = &(lpSelectData->aQueries[nEvents]);
|
|
|
|
aEvents[nEvents] = CreateEvent(NULL, TRUE, FALSE, NULL);
|
|
|
|
maskEvents = 0;
|
|
|
|
switch (iterQuery->EMode)
|
|
|
|
{
|
|
|
|
case SELECT_MODE_READ:
|
|
|
|
maskEvents = FD_READ | FD_ACCEPT | FD_CLOSE;
|
|
|
|
break;
|
|
|
|
case SELECT_MODE_WRITE:
|
|
|
|
maskEvents = FD_WRITE | FD_CONNECT | FD_CLOSE;
|
|
|
|
break;
|
|
|
|
case SELECT_MODE_EXCEPT:
|
|
|
|
maskEvents = FD_OOB;
|
|
|
|
break;
|
|
|
|
}
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
|
2008-07-29 01:31:41 -07:00
|
|
|
check_error(lpSelectData,
|
|
|
|
WSAEventSelect(
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
(SOCKET)(iterQuery->hFileDescr),
|
|
|
|
aEvents[nEvents],
|
2008-07-29 01:31:41 -07:00
|
|
|
maskEvents) == SOCKET_ERROR);
|
|
|
|
}
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
|
2008-07-29 01:31:41 -07:00
|
|
|
/* Add stop event */
|
|
|
|
aEvents[nEvents] = hStop;
|
|
|
|
nEvents++;
|
|
|
|
|
|
|
|
if (lpSelectData->nError == 0)
|
|
|
|
{
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
check_error(lpSelectData,
|
2008-07-29 01:31:41 -07:00
|
|
|
WaitForMultipleObjects(
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
nEvents,
|
|
|
|
aEvents,
|
|
|
|
FALSE,
|
2008-07-29 01:31:41 -07:00
|
|
|
INFINITE) == WAIT_FAILED);
|
|
|
|
};
|
|
|
|
|
|
|
|
if (lpSelectData->nError == 0)
|
|
|
|
{
|
|
|
|
for (i = 0; i < lpSelectData->nQueriesCount; i++)
|
|
|
|
{
|
|
|
|
iterQuery = &(lpSelectData->aQueries[i]);
|
|
|
|
if (WaitForSingleObject(aEvents[i], 0) == WAIT_OBJECT_0)
|
|
|
|
{
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Socket %d has pending events", (i - 1));
|
2008-07-29 01:31:41 -07:00
|
|
|
if (iterQuery != NULL)
|
|
|
|
{
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
select_data_result_add(lpSelectData, iterQuery->EMode, iterQuery->lpOrigIdx);
|
2008-07-29 01:31:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* WSAEventSelect() automatically sets socket to nonblocking mode.
|
|
|
|
Restore the blocking one. */
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
if (iterQuery->uFlagsFd & FLAGS_FD_IS_BLOCKING)
|
|
|
|
{
|
|
|
|
DEBUG_PRINT("Restore a blocking socket");
|
2011-10-15 02:02:22 -07:00
|
|
|
iMode = 0;
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
check_error(lpSelectData,
|
|
|
|
WSAEventSelect((SOCKET)(iterQuery->hFileDescr), aEvents[i], 0) != 0 ||
|
|
|
|
ioctlsocket((SOCKET)(iterQuery->hFileDescr), FIONBIO, &iMode) != 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
check_error(lpSelectData,
|
|
|
|
WSAEventSelect((SOCKET)(iterQuery->hFileDescr), aEvents[i], 0) != 0);
|
|
|
|
};
|
2008-07-29 01:31:41 -07:00
|
|
|
|
|
|
|
CloseHandle(aEvents[i]);
|
|
|
|
aEvents[i] = INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add a function to monitor socket */
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
LPSELECTDATA socket_poll_add (LPSELECTDATA lpSelectData,
|
|
|
|
SELECTMODE EMode,
|
|
|
|
HANDLE hFileDescr,
|
|
|
|
int lpOrigIdx,
|
|
|
|
unsigned int uFlagsFd)
|
2008-07-29 01:31:41 -07:00
|
|
|
{
|
|
|
|
LPSELECTDATA res;
|
|
|
|
LPSELECTDATA hd;
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
|
2008-07-29 01:31:41 -07:00
|
|
|
hd = lpSelectData;
|
|
|
|
/* Polling socket can be done mulitple handle at the same time. You just
|
|
|
|
need one worker to use it. Try to find if there is already a worker
|
|
|
|
handling this kind of request.
|
|
|
|
*/
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Scanning list of worker to find one that already handle socket");
|
2008-07-29 01:31:41 -07:00
|
|
|
res = select_data_job_search(&hd, SELECT_TYPE_SOCKET);
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
|
2008-07-29 01:31:41 -07:00
|
|
|
/* Add a new socket to poll */
|
|
|
|
res->funcWorker = socket_poll;
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Add socket %x to worker", hFileDescr);
|
|
|
|
select_data_query_add(res, EMode, hFileDescr, lpOrigIdx, uFlagsFd);
|
|
|
|
DEBUG_PRINT("Socket %x added", hFileDescr);
|
2008-07-29 01:31:41 -07:00
|
|
|
|
|
|
|
return hd;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************/
|
|
|
|
/* Static */
|
|
|
|
/***********************/
|
|
|
|
|
|
|
|
/* Add a static result */
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
LPSELECTDATA static_poll_add (LPSELECTDATA lpSelectData,
|
|
|
|
SELECTMODE EMode,
|
|
|
|
HANDLE hFileDescr,
|
|
|
|
int lpOrigIdx,
|
|
|
|
unsigned int uFlagsFd)
|
1997-09-04 06:45:56 -07:00
|
|
|
{
|
2008-07-29 01:31:41 -07:00
|
|
|
LPSELECTDATA res;
|
|
|
|
LPSELECTDATA hd;
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
|
2008-07-29 01:31:41 -07:00
|
|
|
/* Look for an already initialized static element */
|
|
|
|
hd = lpSelectData;
|
|
|
|
res = select_data_job_search(&hd, SELECT_TYPE_STATIC);
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
|
2008-07-29 01:31:41 -07:00
|
|
|
/* Add a new query/result */
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
select_data_query_add(res, EMode, hFileDescr, lpOrigIdx, uFlagsFd);
|
|
|
|
select_data_result_add(res, EMode, lpOrigIdx);
|
2008-07-29 01:31:41 -07:00
|
|
|
|
|
|
|
return hd;
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************/
|
|
|
|
/* Generic select data handling */
|
|
|
|
/********************************/
|
|
|
|
|
|
|
|
/* Guess handle type */
|
|
|
|
static SELECTHANDLETYPE get_handle_type(value fd)
|
|
|
|
{
|
|
|
|
DWORD mode;
|
|
|
|
SELECTHANDLETYPE res;
|
|
|
|
|
|
|
|
CAMLparam1(fd);
|
|
|
|
|
|
|
|
mode = 0;
|
|
|
|
res = SELECT_HANDLE_NONE;
|
|
|
|
|
|
|
|
if (Descr_kind_val(fd) == KIND_SOCKET)
|
|
|
|
{
|
|
|
|
res = SELECT_HANDLE_SOCKET;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch(GetFileType(Handle_val(fd)))
|
|
|
|
{
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
case FILE_TYPE_DISK:
|
2008-07-29 01:31:41 -07:00
|
|
|
res = SELECT_HANDLE_DISK;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FILE_TYPE_CHAR: /* character file or a console */
|
|
|
|
if (GetConsoleMode(Handle_val(fd), &mode) != 0)
|
|
|
|
{
|
|
|
|
res = SELECT_HANDLE_CONSOLE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res = SELECT_HANDLE_NONE;
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FILE_TYPE_PIPE: /* a named or an anonymous pipe (socket already handled) */
|
|
|
|
res = SELECT_HANDLE_PIPE;
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
CAMLreturnT(SELECTHANDLETYPE, res);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Choose what to do with given data */
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
LPSELECTDATA select_data_dispatch (LPSELECTDATA lpSelectData, SELECTMODE EMode, value fd, int lpOrigIdx)
|
2008-07-29 01:31:41 -07:00
|
|
|
{
|
|
|
|
LPSELECTDATA res;
|
|
|
|
HANDLE hFileDescr;
|
|
|
|
struct sockaddr sa;
|
|
|
|
int sa_len;
|
|
|
|
BOOL alreadyAdded;
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
unsigned int uFlagsFd;
|
2008-07-29 01:31:41 -07:00
|
|
|
|
|
|
|
CAMLparam1(fd);
|
|
|
|
|
|
|
|
res = lpSelectData;
|
|
|
|
hFileDescr = Handle_val(fd);
|
|
|
|
sa_len = sizeof(sa);
|
|
|
|
alreadyAdded = FALSE;
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
uFlagsFd = Flags_fd_val(fd);
|
2008-07-29 01:31:41 -07:00
|
|
|
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Begin dispatching handle %x", hFileDescr);
|
2008-07-29 01:31:41 -07:00
|
|
|
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Waiting for %d on handle %x", EMode, hFileDescr);
|
|
|
|
|
|
|
|
/* There is only 2 way to have except mode: transmission of OOB data through
|
2008-07-29 01:31:41 -07:00
|
|
|
a socket TCP/IP and through a strange interaction with a TTY.
|
|
|
|
With windows, we only consider the TCP/IP except condition
|
|
|
|
*/
|
|
|
|
switch(get_handle_type(fd))
|
|
|
|
{
|
|
|
|
case SELECT_HANDLE_DISK:
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Handle %x is a disk handle", hFileDescr);
|
2008-07-29 01:31:41 -07:00
|
|
|
/* Disk is always ready in read/write operation */
|
|
|
|
if (EMode == SELECT_MODE_READ || EMode == SELECT_MODE_WRITE)
|
|
|
|
{
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
res = static_poll_add(res, EMode, hFileDescr, lpOrigIdx, uFlagsFd);
|
2008-07-29 01:31:41 -07:00
|
|
|
};
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SELECT_HANDLE_CONSOLE:
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Handle %x is a console handle", hFileDescr);
|
2008-07-29 01:31:41 -07:00
|
|
|
/* Console is always ready in write operation, need to check for read. */
|
|
|
|
if (EMode == SELECT_MODE_READ)
|
|
|
|
{
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
res = read_console_poll_add(res, EMode, hFileDescr, lpOrigIdx, uFlagsFd);
|
2003-01-06 08:44:21 -08:00
|
|
|
}
|
2008-07-29 01:31:41 -07:00
|
|
|
else if (EMode == SELECT_MODE_WRITE)
|
|
|
|
{
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
res = static_poll_add(res, EMode, hFileDescr, lpOrigIdx, uFlagsFd);
|
2008-07-29 01:31:41 -07:00
|
|
|
};
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SELECT_HANDLE_PIPE:
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Handle %x is a pipe handle", hFileDescr);
|
2008-07-29 01:31:41 -07:00
|
|
|
/* Console is always ready in write operation, need to check for read. */
|
|
|
|
if (EMode == SELECT_MODE_READ)
|
|
|
|
{
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Need to check availability of data on pipe");
|
|
|
|
res = read_pipe_poll_add(res, EMode, hFileDescr, lpOrigIdx, uFlagsFd);
|
2003-01-06 08:44:21 -08:00
|
|
|
}
|
2008-07-29 01:31:41 -07:00
|
|
|
else if (EMode == SELECT_MODE_WRITE)
|
|
|
|
{
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("No need to check availability of data on pipe, write operation always possible");
|
|
|
|
res = static_poll_add(res, EMode, hFileDescr, lpOrigIdx, uFlagsFd);
|
2008-07-29 01:31:41 -07:00
|
|
|
};
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SELECT_HANDLE_SOCKET:
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Handle %x is a socket handle", hFileDescr);
|
2008-07-29 01:31:41 -07:00
|
|
|
if (getsockname((SOCKET)hFileDescr, &sa, &sa_len) == SOCKET_ERROR)
|
|
|
|
{
|
|
|
|
if (WSAGetLastError() == WSAEINVAL)
|
|
|
|
{
|
|
|
|
/* Socket is not bound */
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Socket is not connected");
|
2008-07-29 01:31:41 -07:00
|
|
|
if (EMode == SELECT_MODE_WRITE || EMode == SELECT_MODE_READ)
|
|
|
|
{
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
res = static_poll_add(res, EMode, hFileDescr, lpOrigIdx, uFlagsFd);
|
2008-07-29 01:31:41 -07:00
|
|
|
alreadyAdded = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2003-01-06 08:44:21 -08:00
|
|
|
}
|
2008-07-29 01:31:41 -07:00
|
|
|
if (!alreadyAdded)
|
|
|
|
{
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
res = socket_poll_add(res, EMode, hFileDescr, lpOrigIdx, uFlagsFd);
|
2008-07-29 01:31:41 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Handle %x is unknown", hFileDescr);
|
|
|
|
win32_maperr(ERROR_INVALID_HANDLE);
|
|
|
|
uerror("select", Nothing);
|
2008-07-29 01:31:41 -07:00
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Finish dispatching handle %x", hFileDescr);
|
2008-07-29 01:31:41 -07:00
|
|
|
|
|
|
|
CAMLreturnT(LPSELECTDATA, res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD caml_list_length (value lst)
|
|
|
|
{
|
|
|
|
DWORD res;
|
|
|
|
|
|
|
|
CAMLparam1 (lst);
|
|
|
|
CAMLlocal1 (l);
|
|
|
|
|
|
|
|
for (res = 0, l = lst; l != Val_int(0); l = Field(l, 1), res++)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
CAMLreturnT(DWORD, res);
|
|
|
|
}
|
|
|
|
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
static value find_handle(LPSELECTRESULT iterResult, value readfds, value writefds, value exceptfds)
|
|
|
|
{
|
|
|
|
CAMLparam3(readfds, writefds, exceptfds);
|
|
|
|
CAMLlocal2(result, list);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
switch( iterResult->EMode )
|
|
|
|
{
|
|
|
|
case SELECT_MODE_READ:
|
|
|
|
list = readfds;
|
|
|
|
break;
|
|
|
|
case SELECT_MODE_WRITE:
|
|
|
|
list = writefds;
|
|
|
|
break;
|
|
|
|
case SELECT_MODE_EXCEPT:
|
|
|
|
list = exceptfds;
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
|
|
|
for(i=0; list != Val_unit && i < iterResult->lpOrigIdx; ++i )
|
|
|
|
{
|
|
|
|
list = Field(list, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (list == Val_unit)
|
|
|
|
failwith ("select.c: original file handle not found");
|
|
|
|
|
|
|
|
result = Field(list, 0);
|
|
|
|
|
|
|
|
CAMLreturn( result );
|
|
|
|
}
|
|
|
|
|
2008-07-29 01:31:41 -07:00
|
|
|
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
|
|
|
|
|
|
|
CAMLprim value unix_select(value readfds, value writefds, value exceptfds, value timeout)
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
{
|
2008-07-29 01:31:41 -07:00
|
|
|
/* Event associated to handle */
|
|
|
|
DWORD nEventsCount;
|
|
|
|
DWORD nEventsMax;
|
|
|
|
HANDLE *lpEventsDone;
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
|
2008-07-29 01:31:41 -07:00
|
|
|
/* Data for all handles */
|
|
|
|
LPSELECTDATA lpSelectData;
|
|
|
|
LPSELECTDATA iterSelectData;
|
|
|
|
|
|
|
|
/* Iterator for results */
|
|
|
|
LPSELECTRESULT iterResult;
|
|
|
|
|
|
|
|
/* Iterator */
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
/* Error status */
|
|
|
|
DWORD err;
|
|
|
|
|
|
|
|
/* Time to wait */
|
|
|
|
DWORD milliseconds;
|
|
|
|
|
2008-12-03 10:09:09 -08:00
|
|
|
/* Is there static select data */
|
|
|
|
BOOL hasStaticData = FALSE;
|
|
|
|
|
2008-07-29 01:31:41 -07:00
|
|
|
/* Wait return */
|
|
|
|
DWORD waitRet;
|
|
|
|
|
|
|
|
/* Set of handle */
|
|
|
|
SELECTHANDLESET hds;
|
|
|
|
DWORD hdsMax;
|
|
|
|
LPHANDLE hdsData;
|
|
|
|
|
|
|
|
/* Length of each list */
|
|
|
|
DWORD readfds_len;
|
|
|
|
DWORD writefds_len;
|
|
|
|
DWORD exceptfds_len;
|
|
|
|
|
|
|
|
CAMLparam4 (readfds, writefds, exceptfds, timeout);
|
|
|
|
CAMLlocal5 (read_list, write_list, except_list, res, l);
|
|
|
|
CAMLlocal1 (fd);
|
|
|
|
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("in select");
|
2008-07-29 01:31:41 -07:00
|
|
|
|
|
|
|
nEventsCount = 0;
|
|
|
|
nEventsMax = 0;
|
|
|
|
lpEventsDone = NULL;
|
|
|
|
lpSelectData = NULL;
|
|
|
|
iterSelectData = NULL;
|
|
|
|
iterResult = NULL;
|
|
|
|
err = 0;
|
2008-12-03 10:09:09 -08:00
|
|
|
hasStaticData = 0;
|
2008-07-29 01:31:41 -07:00
|
|
|
waitRet = 0;
|
|
|
|
readfds_len = caml_list_length(readfds);
|
|
|
|
writefds_len = caml_list_length(writefds);
|
|
|
|
exceptfds_len = caml_list_length(exceptfds);
|
|
|
|
hdsMax = MAX(readfds_len, MAX(writefds_len, exceptfds_len));
|
|
|
|
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
hdsData = (HANDLE *)caml_stat_alloc(sizeof(HANDLE) * hdsMax);
|
2008-07-29 01:31:41 -07:00
|
|
|
|
|
|
|
if (Double_val(timeout) >= 0.0)
|
|
|
|
{
|
|
|
|
milliseconds = 1000 * Double_val(timeout);
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Will wait %d ms", milliseconds);
|
2008-07-29 01:31:41 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
milliseconds = INFINITE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Create list of select data, based on the different list of fd to watch */
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Dispatch read fd");
|
2008-07-29 01:31:41 -07:00
|
|
|
handle_set_init(&hds, hdsData, hdsMax);
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
i=0;
|
2008-07-29 01:31:41 -07:00
|
|
|
for (l = readfds; l != Val_int(0); l = Field(l, 1))
|
|
|
|
{
|
|
|
|
fd = Field(l, 0);
|
|
|
|
if (!handle_set_mem(&hds, Handle_val(fd)))
|
|
|
|
{
|
|
|
|
handle_set_add(&hds, Handle_val(fd));
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
lpSelectData = select_data_dispatch(lpSelectData, SELECT_MODE_READ, fd, i++);
|
2008-07-29 01:31:41 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Discarding handle %x which is already monitor for read", Handle_val(fd));
|
2008-07-29 01:31:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
handle_set_reset(&hds);
|
|
|
|
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Dispatch write fd");
|
2008-07-29 01:31:41 -07:00
|
|
|
handle_set_init(&hds, hdsData, hdsMax);
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
i=0;
|
2008-07-29 01:31:41 -07:00
|
|
|
for (l = writefds; l != Val_int(0); l = Field(l, 1))
|
|
|
|
{
|
|
|
|
fd = Field(l, 0);
|
|
|
|
if (!handle_set_mem(&hds, Handle_val(fd)))
|
|
|
|
{
|
|
|
|
handle_set_add(&hds, Handle_val(fd));
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
lpSelectData = select_data_dispatch(lpSelectData, SELECT_MODE_WRITE, fd, i++);
|
2008-07-29 01:31:41 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Discarding handle %x which is already monitor for write", Handle_val(fd));
|
2008-07-29 01:31:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
handle_set_reset(&hds);
|
|
|
|
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Dispatch exceptional fd");
|
2008-07-29 01:31:41 -07:00
|
|
|
handle_set_init(&hds, hdsData, hdsMax);
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
i=0;
|
2008-07-29 01:31:41 -07:00
|
|
|
for (l = exceptfds; l != Val_int(0); l = Field(l, 1))
|
|
|
|
{
|
|
|
|
fd = Field(l, 0);
|
|
|
|
if (!handle_set_mem(&hds, Handle_val(fd)))
|
|
|
|
{
|
|
|
|
handle_set_add(&hds, Handle_val(fd));
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
lpSelectData = select_data_dispatch(lpSelectData, SELECT_MODE_EXCEPT, fd, i++);
|
2008-07-29 01:31:41 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Discarding handle %x which is already monitor for exceptional", Handle_val(fd));
|
2008-07-29 01:31:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
handle_set_reset(&hds);
|
|
|
|
|
|
|
|
/* Building the list of handle to wait for */
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Building events done array");
|
2008-07-29 01:31:41 -07:00
|
|
|
nEventsMax = list_length((LPLIST)lpSelectData);
|
|
|
|
nEventsCount = 0;
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
lpEventsDone = (HANDLE *)caml_stat_alloc(sizeof(HANDLE) * nEventsMax);
|
2008-07-29 01:31:41 -07:00
|
|
|
|
|
|
|
iterSelectData = lpSelectData;
|
|
|
|
while (iterSelectData != NULL)
|
|
|
|
{
|
2008-12-03 10:09:09 -08:00
|
|
|
/* Check if it is static data. If this is the case, launch everything
|
|
|
|
* but don't wait for events. It helps to test if there are events on
|
|
|
|
* any other fd (which are not static), knowing that there is at least
|
|
|
|
* one result (the static data).
|
|
|
|
*/
|
|
|
|
if (iterSelectData->EType == SELECT_TYPE_STATIC)
|
|
|
|
{
|
|
|
|
hasStaticData = TRUE;
|
|
|
|
};
|
|
|
|
|
2008-07-29 01:31:41 -07:00
|
|
|
/* Execute APC */
|
|
|
|
if (iterSelectData->funcWorker != NULL)
|
|
|
|
{
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
iterSelectData->lpWorker =
|
2008-07-29 01:31:41 -07:00
|
|
|
worker_job_submit(
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
iterSelectData->funcWorker,
|
2008-07-29 01:31:41 -07:00
|
|
|
(void *)iterSelectData);
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Job submitted to worker %x", iterSelectData->lpWorker);
|
2008-07-29 01:31:41 -07:00
|
|
|
lpEventsDone[nEventsCount] = worker_job_event_done(iterSelectData->lpWorker);
|
|
|
|
nEventsCount++;
|
|
|
|
};
|
|
|
|
iterSelectData = LIST_NEXT(LPSELECTDATA, iterSelectData);
|
|
|
|
};
|
|
|
|
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Need to watch %d workers", nEventsCount);
|
2008-07-29 01:31:41 -07:00
|
|
|
|
|
|
|
/* Processing select itself */
|
|
|
|
enter_blocking_section();
|
|
|
|
/* There are worker started, waiting to be monitored */
|
|
|
|
if (nEventsCount > 0)
|
|
|
|
{
|
|
|
|
/* Waiting for event */
|
2008-12-03 10:09:09 -08:00
|
|
|
if (err == 0 && !hasStaticData)
|
2008-07-29 01:31:41 -07:00
|
|
|
{
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Waiting for one select worker to be done");
|
2008-07-29 01:31:41 -07:00
|
|
|
switch (WaitForMultipleObjects(nEventsCount, lpEventsDone, FALSE, milliseconds))
|
|
|
|
{
|
|
|
|
case WAIT_FAILED:
|
|
|
|
err = GetLastError();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WAIT_TIMEOUT:
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Select timeout");
|
2008-07-29 01:31:41 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("One worker is done");
|
2008-07-29 01:31:41 -07:00
|
|
|
break;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ordering stop to every worker */
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Sending stop signal to every select workers");
|
2008-07-29 01:31:41 -07:00
|
|
|
iterSelectData = lpSelectData;
|
|
|
|
while (iterSelectData != NULL)
|
|
|
|
{
|
|
|
|
if (iterSelectData->lpWorker != NULL)
|
|
|
|
{
|
|
|
|
worker_job_stop(iterSelectData->lpWorker);
|
|
|
|
};
|
|
|
|
iterSelectData = LIST_NEXT(LPSELECTDATA, iterSelectData);
|
|
|
|
};
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
|
|
|
|
DEBUG_PRINT("Waiting for every select worker to be done");
|
2008-07-29 01:31:41 -07:00
|
|
|
switch (WaitForMultipleObjects(nEventsCount, lpEventsDone, TRUE, INFINITE))
|
|
|
|
{
|
|
|
|
case WAIT_FAILED:
|
|
|
|
err = GetLastError();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Every worker is done");
|
2008-07-29 01:31:41 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Nothing to monitor but some time to wait. */
|
2008-12-03 10:09:09 -08:00
|
|
|
else if (!hasStaticData)
|
2008-07-29 01:31:41 -07:00
|
|
|
{
|
|
|
|
Sleep(milliseconds);
|
|
|
|
}
|
|
|
|
leave_blocking_section();
|
|
|
|
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Error status: %d (0 is ok)", err);
|
2008-07-29 01:31:41 -07:00
|
|
|
/* Build results */
|
|
|
|
if (err == 0)
|
|
|
|
{
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Building result");
|
|
|
|
read_list = Val_unit;
|
2008-07-29 01:31:41 -07:00
|
|
|
write_list = Val_unit;
|
|
|
|
except_list = Val_unit;
|
|
|
|
|
|
|
|
iterSelectData = lpSelectData;
|
|
|
|
while (iterSelectData != NULL)
|
|
|
|
{
|
|
|
|
for (i = 0; i < iterSelectData->nResultsCount; i++)
|
|
|
|
{
|
|
|
|
iterResult = &(iterSelectData->aResults[i]);
|
|
|
|
l = alloc_small(2, 0);
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
Store_field(l, 0, find_handle(iterResult, readfds, writefds, exceptfds));
|
2008-07-29 01:31:41 -07:00
|
|
|
switch (iterResult->EMode)
|
|
|
|
{
|
|
|
|
case SELECT_MODE_READ:
|
|
|
|
Store_field(l, 1, read_list);
|
|
|
|
read_list = l;
|
|
|
|
break;
|
|
|
|
case SELECT_MODE_WRITE:
|
|
|
|
Store_field(l, 1, write_list);
|
|
|
|
write_list = l;
|
|
|
|
break;
|
|
|
|
case SELECT_MODE_EXCEPT:
|
|
|
|
Store_field(l, 1, except_list);
|
|
|
|
except_list = l;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* We try to only process the first error, bypass other errors */
|
|
|
|
if (err == 0 && iterSelectData->EState == SELECT_STATE_ERROR)
|
|
|
|
{
|
|
|
|
err = iterSelectData->nError;
|
|
|
|
}
|
|
|
|
iterSelectData = LIST_NEXT(LPSELECTDATA, iterSelectData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free resources */
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Free selectdata resources");
|
2008-07-29 01:31:41 -07:00
|
|
|
iterSelectData = lpSelectData;
|
|
|
|
while (iterSelectData != NULL)
|
|
|
|
{
|
|
|
|
lpSelectData = iterSelectData;
|
|
|
|
iterSelectData = LIST_NEXT(LPSELECTDATA, iterSelectData);
|
|
|
|
select_data_free(lpSelectData);
|
|
|
|
}
|
|
|
|
lpSelectData = NULL;
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
|
2008-07-29 01:31:41 -07:00
|
|
|
/* Free allocated events/handle set array */
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Free local allocated resources");
|
|
|
|
caml_stat_free(lpEventsDone);
|
|
|
|
caml_stat_free(hdsData);
|
2008-07-29 01:31:41 -07:00
|
|
|
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Raise error if required");
|
2008-07-29 01:31:41 -07:00
|
|
|
if (err != 0)
|
|
|
|
{
|
|
|
|
win32_maperr(err);
|
|
|
|
uerror("select", Nothing);
|
|
|
|
}
|
|
|
|
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("Build final result");
|
2008-07-29 01:31:41 -07:00
|
|
|
res = alloc_small(3, 0);
|
|
|
|
Store_field(res, 0, read_list);
|
|
|
|
Store_field(res, 1, write_list);
|
|
|
|
Store_field(res, 2, except_list);
|
|
|
|
|
Patch provided by Sylvain Le Gall:
- Fix #4894: Windows (mingw): Unix.select and non-blocking sockets,
add a filedescr.flags_fd in win32unix/unixsupport.h. It contains the
non-blocking status of the associated filedescr and helps to restore
this status after a select.
- Fix #4789: Windows: Unix.select failing with EPIPE error,
Apply patch provided by J. Vouillon
- Fix #4973: Failure "Unknown handle",
Be consistent between Windows and Linux, raise an EBADF Unix_error
for a closed pipe handle.
- Fix #4844: Unix.select bug (triggered if linked against threads),
Apply patch by C. Bauer, replace lpOrig by lpOrigIdx which can survive
a GC collection
For otherlibs/win32unix/{select|windbug}.c:
- Remove Heap* fucntions to allocate/free memory and replace it by
caml_stat_* function, which are more OCaml compliant
- Rework DBUG message, use DEBUG_PRINT rather than #ifdef DBUG... #endif
and use DEBUG variable (more OCaml compliant), also remove dbug_init
functions and use a static variable to replace it (subject to race
condition but this not really important, because every path lead to
same initialization)
- Use a fast start scheme for pipe polling, rather than always waiting
10ms, start by 1, 2, 4, 8 and then 10ms. The 4 first times give select
a chance to a fast answer.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10467 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2010-05-25 06:01:06 -07:00
|
|
|
DEBUG_PRINT("out select");
|
2008-07-29 01:31:41 -07:00
|
|
|
|
|
|
|
CAMLreturn(res);
|
1997-09-04 06:45:56 -07:00
|
|
|
}
|