| From: | Heikki Linnakangas <hlinnakangas(at)vmware(dot)com> | 
|---|---|
| To: | Kyotaro HORIGUCHI <horiguchi(dot)kyotaro(at)lab(dot)ntt(dot)co(dot)jp> | 
| Cc: | <robertmhaas(at)gmail(dot)com>, <pgsql-hackers(at)postgresql(dot)org> | 
| Subject: | Re: Escaping from blocked send() reprised. | 
| Date: | 2014-09-02 18:22:29 | 
| Message-ID: | 54060AE5.5020502@vmware.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-hackers | 
On 08/28/2014 03:47 PM, Kyotaro HORIGUCHI wrote:
>    To make the code mentioned above (Patch 0002) tidy, rewrite the
>    socket emulation code for win32 backends so that each socket
>    can have its own non-blocking state. (patch 0001)
The first patch that makes non-blocking sockets behave more sanely on 
Windows seems like a good idea, independently of the second patch. I'm 
looking at the first patch now, I'll make a separate post about the 
second patch.
> Some concern about this patch,
>
> - This patch allows the number of non-blocking socket to be below
>    64 (FD_SETSIZE) on win32 backend but it seems to be sufficient.
Yeah, that's plenty.
> - This patch introduced redundant socket emulation for win32
>    backend but win32 bare socket for Port is already nonblocking
>    as described so it donsn't seem to be a serious problem on
>    performance. Addition to it, since I don't know the reason why
>    win32/socket.c provides the blocking-mode socket emulation, I
>    decided to preserve win32/socket.c to have blocking socket
>    emulation. Possibly it can be removed.
On Windows, the backend has an emulation layer for POSIX signals, which 
uses threads and Windows events. The reason win32/socket.c always uses 
non-blocking mode internally is that it needs to wait for the socket to 
become readable/writeable, and for the signal-emulation event, at the 
same time. So no, we can't remove it.
The approach taken in the first patch seems sensible. I changed it to 
not use FD_SET, though. A custom array seems better, that way we don't 
need the pgwin32_nonblockset_init() call, we can just use initialize the 
variable. It's a little bit more code, but it's well-contained in 
win32/socket.c. Please take a look, to double-check that I didn't screw up.
- Heikki
| Attachment | Content-Type | Size | 
|---|---|---|
| improve-nonblocking-sockets-on-windows-1.patch | text/x-diff | 7.9 KB | 
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Heikki Linnakangas | 2014-09-02 18:46:29 | Re: Escaping from blocked send() reprised. | 
| Previous Message | Marko Tiikkaja | 2014-09-02 18:20:02 | Re: PL/pgSQL 2 |