How to close TInetServer without except?

classic Classic list List threaded Threaded
47 messages Options
123
Reply | Threaded
Open this post in threaded view
|

Re: How to close TInetServer without except?

Marco van de Voort
In our previous episode, Ewald said:
>
> The point being that the answer to one of the OP sub-problems [the one
> quoted _partially_ above], can be to either use:
> - pthread_cancel() [overkill, I know, but nonetheless a solution]
> - non-blocking sockets [not very code-efficient IMHO if you only want to
> exit an application gracefully (high code versus ouput ratio)]
> - something different (one can try experimenting with shutting down the
> listening socket, using signals, ... but I haven't done so, so I can't
> give any feedback on this)

Select on the main socket before doing the accept?
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to close TInetServer without except?

silvioprog

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to close TInetServer without except?

zaher dirkey
In reply to this post by Marco van de Voort

On Fri, May 3, 2013 at 9:13 PM, Marco van de Voort <[hidden email]> wrote:
Select on the main socket before doing the accept?

​No i am not use Select before Accept, accept is blocking the thread.

Best Regards
Zaher Dirkey

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to close TInetServer without except?

Ewald-2
In reply to this post by Marco van de Voort

On 03 May 2013, at 20:13, Marco van de Voort wrote:

> In our previous episode, Ewald said:
>>
>> The point being that the answer to one of the OP sub-problems [the one
>> quoted _partially_ above], can be to either use:
>> - pthread_cancel() [overkill, I know, but nonetheless a solution]
>> - non-blocking sockets [not very code-efficient IMHO if you only want to
>> exit an application gracefully (high code versus ouput ratio)]
>> - something different (one can try experimenting with shutting down the
>> listening socket, using signals, ... but I haven't done so, so I can't
>> give any feedback on this)
>
> Select on the main socket before doing the accept?

Yep, possibly the most simple and effective recipe (not much code to add, no radical changes, no overkill). Shame on me for not thinking of that ;-)

--
Ewald

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to close TInetServer without except?

Marco van de Voort
In reply to this post by zaher dirkey
In our previous episode, Zaher Dirkey said:
> On Fri, May 3, 2013 at 9:13 PM, Marco van de Voort <[hidden email]> wrote:
>
> > Select on the main socket before doing the accept?
>
>
> ?No i am not use Select before Accept, accept is blocking the thread.

That's the point. Don't. Use a select, it has a timeout, and accept only if
select shows activity on the listened to socket.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to close TInetServer without except?

zaher dirkey

On Fri, May 3, 2013 at 11:27 PM, Marco van de Voort <[hidden email]> wrote:

That's the point. Don't. Use a select, it has a timeout, and accept only if
select shows activity on the listened to socket.

​Not sure, but i believe i used it in the past and have problems with it, We can leave it to silvio to test it :P​



--
I am using last revision of Lazarus, FPC 2.6 on Windows XP SP3

Best Regards
Zaher Dirkey

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to close TInetServer without except?

zaher dirkey

On Fri, May 3, 2013 at 11:47 PM, Zaher Dirkey <[hidden email]> wrote:
On Fri, May 3, 2013 at 11:27 PM, Marco van de Voort <[hidden email]> wrote:

That's the point. Don't. Use a select, it has a timeout, and accept only if
select shows activity on the listened to socket.

​Not sure, but i believe i used it in the past and have problems with it, We can leave it to silvio to test it :P​

​I use "Select"​ for incoming Data not for incoming client connections!

Best Regards
Zaher Dirkey

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to close TInetServer without except?

Ewald-2

On 03 May 2013, at 22:56, Zaher Dirkey wrote:


On Fri, May 3, 2013 at 11:47 PM, Zaher Dirkey <[hidden email]> wrote:
On Fri, May 3, 2013 at 11:27 PM, Marco van de Voort <[hidden email]> wrote:

That's the point. Don't. Use a select, it has a timeout, and accept only if
select shows activity on the listened to socket.

​Not sure, but i believe i used it in the past and have problems with it, We can leave it to silvio to test it :P​

​I use "Select"​ for incoming Data not for incoming client connections!

It doesn't matter. A few facts:
- You create a listening socket which you pass as an argument to accept().
- A socket is a file descriptor.
- Select operates on file descriptors. Read the man page of select [http://linux.die.net/man/2/select] and you'll see that the exact purpose of select is to query whether or not the next IO operation is going to block.

Now that we have established these two facts, I believe that using select before accept to check whether the latter will block is valid logic, wouldn't you say?

PS: The exact details of this implementation I do not know, I haven't tested.

--
Ewald


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to close TInetServer without except?

Ludo Brands
In reply to this post by silvioprog
On 05/03/2013 05:57 PM, silvioprog wrote:

>
> Could you give me an example in practice? Theoretically I understand,
> but I don't know do in practice. :/
>
> Now, TTcpIpServer is working well. The new problem is: when I close the
> server with one or more clients connected, I got a memory leak.
>

Take a look at TBlockSocket.InternalCanRead and TBlockSocket.CanRead in
synapse on how to set up select correctly. Then do something like

repeat
  if Socket.CanRead(timeout) then
    begin
    insock:=Socket.Accept;
    if insock<>-1 then
      //start working with insock
    else
      //deal with error
    end;
until ThreadTerminated;

Ludo
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to close TInetServer without except?

silvioprog
2013/5/4 Ludo Brands <[hidden email]>
On 05/03/2013 05:57 PM, silvioprog wrote:
> Could you give me an example in practice? Theoretically I understand,
> but I don't know do in practice. :/
>
> Now, TTcpIpServer is working well. The new problem is: when I close the
> server with one or more clients connected, I got a memory leak.
>

Take a look at TBlockSocket.InternalCanRead and TBlockSocket.CanRead in
synapse on how to set up select correctly. Then do something like

repeat
  if Socket.CanRead(timeout) then
    begin
    insock:=Socket.Accept;
    if insock<>-1 then
      //start working with insock
    else
      //deal with error
    end;
until ThreadTerminated;

Ludo

Thank you!

--
Silvio Clécio
My public projects - github.com/silvioprog

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to close TInetServer without except?

zaher dirkey

On Sat, May 4, 2013 at 8:47 AM, silvioprog <[hidden email]> wrote:
repeat
  if Socket.CanRead(timeout) then
    begin
    insock:=Socket.Accept;
    if insock<>-1 then
      //start working with insock
    else
      //deal with error
    end;
until ThreadTerminated;

Ludo

Thank you!

​If you success, tell us, i must fix my sockets too :)​



--
I am using last revision of Lazarus, FPC 2.6 on Windows XP SP3

Best Regards
Zaher Dirkey

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to close TInetServer without except?

zaher dirkey
In reply to this post by Ludo Brands

On Sat, May 4, 2013 at 8:45 AM, Ludo Brands <[hidden email]> wrote:
Take a look at TBlockSocket.InternalCanRead and TBlockSocket.CanRead in
synapse on how to set up select correctly. Then do something like

repeat
  if Socket.CanRead(timeout) then
    begin
    insock:=Socket.Accept;
    if insock<>-1 then
      //start working with insock
    else
      //deal with error
    end;
until ThreadTerminated;

​I have put Select before Accept and it doesn't work, it blocked forever​ without accepting any connection.
Accept function who block the thread and get new connection.

Best Regards
Zaher Dirkey

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to close TInetServer without except?

Ludo Brands
On 05/04/2013 04:31 PM, Zaher Dirkey wrote:
>
>
> ​I have put Select before Accept and it doesn't work, it blocked forever
> ​ without accepting any connection.
> Accept function who block the thread and get new connection.
>

Can you show the code you use? You tested on Windows, linux, Mac, ...?

Ludo


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to close TInetServer without except?

zaher dirkey

On Sat, May 4, 2013 at 5:40 PM, Ludo Brands <[hidden email]> wrote:
Can you show the code you use? You tested on Windows, linux, Mac, ...?

​Only on Windows XP

about line 323
i changed it to similar to this, but not committed it

      begin
        if Socket.Select(10000, slRead) = erNone then
​ <--- Blocked here forever​

          aSocket := Socket.Accept
        else
          aSocket := nil;
        Enter;

I am using last revision of Lazarus, FPC 2.6 on Windows XP SP3

Best Regards
Zaher Dirkey

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to close TInetServer without except?

zaher dirkey
But mnServer is works with me for a years, and there is mnHttpServer demo and it is work fine too without Select before Accept
https://sourceforge.net/p/minilib/source/ci/master/tree/socket/demo/lazarus/


On Sat, May 4, 2013 at 6:05 PM, Zaher Dirkey <[hidden email]> wrote:

On Sat, May 4, 2013 at 5:40 PM, Ludo Brands <[hidden email]> wrote:
Can you show the code you use? You tested on Windows, linux, Mac, ...?

​Only on Windows XP

about line 323
i changed it to similar to this, but not committed it

      begin
        if Socket.Select(10000, slRead) = erNone then
​ <--- Blocked here forever​

          aSocket := Socket.Accept
        else
          aSocket := nil;
        Enter;

I am using last revision of Lazarus, FPC 2.6 on Windows XP SP3

Best Regards
Zaher Dirkey



--
I am using last revision of Lazarus, FPC 2.6 on Windows XP SP3

Best Regards
Zaher Dirkey

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to close TInetServer without except?

Ludo Brands
In reply to this post by zaher dirkey
On 05/04/2013 05:05 PM, Zaher Dirkey wrote:
>
> On Sat, May 4, 2013 at 5:40 PM, Ludo Brands <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Can you show the code you use? You tested on Windows, linux, Mac, ...?
>
>
> ​Only on Windows XP
>


This is a small test program that works for me on XP and linux:

program testselect;

{$mode objfpc}{$H+}

uses
  Classes,sockets,
  {$ifdef unix}
  unix,baseunix,unixtype
  {$else}
  ctypes,WinSock2
  {$endif}
  ;

CONST
  LISTENPORT=1234;
var
  sock: cint;
  sa,clsa:sockaddr;
  tv:TTimeVal;
  readfds,writefds,exceptfds:tfdset;
  c: Integer;
  res: cint;
  len: tsocklen;
  one: Integer;
begin
  sock:=fpsocket(AF_INET, SOCK_STREAM, 0);
  if sock=-1 then
    begin
    writeln('socket failed with ',socketerror);
    exit;
    end;
  one:=1;
  if fpsetsockopt(sock, SOL_SOCKET, SO_REUSEADDR, @one, sizeof(one))=-1 then
    begin
    writeln('setsockopt failed with ',socketerror);
    exit;
    end;
  fillchar(sa,sizeof(sa),0);
  sa.sin_port:=htons(LISTENPORT);
  sa.sin_family:=AF_INET;
  sa.sin_addr.s_addr:= INADDR_ANY;
  if fpbind(sock,@sa,sizeof(sa))=-1 then
    begin
    writeln('bind failed with ',socketerror);
    exit;
    end;
  if fplisten(sock,10)=-1 then
    begin
    writeln('listen failed with ',socketerror);
    exit;
    end;
  c:=1;
  repeat
    tv.tv_sec:=1;
    tv.tv_usec:=0;
    {$ifdef unix}
    fpFD_ZERO(readfds);
    fpFD_ZERO(writefds);
    fpFD_ZERO(exceptfds);
    fpFD_SET(sock,readfds);
    res:=fpselect(sock+1,@readfds,@writefds,@exceptfds,@tv);
    if (res=-1) and (socketerror<>ESYSEINTR) then
        begin
        writeln('select failed with ',socketerror);
        exit;
        end;
    if (res>0) and (fpFD_ISSET(sock,readfds)<>0) then
      begin
    {$else}
    FD_ZERO(readfds);
    FD_ZERO(writefds);
    FD_ZERO(exceptfds);
    FD_SET(sock,readfds);
    res:=select(sock+1,@readfds,@writefds,@exceptfds,@tv);
    if (res=-1) and (socketerror<>WSAEINTR) then
       begin
       writeln('select failed with ',socketerror);
       exit;
       end;
    if (res>0) and (FD_ISSET(sock,readfds)) then
      begin
    {$endif}
      fillchar(clsa,sizeof(clsa),0);
      len:=sizeof(clsa);
      if fpaccept(sock,@clsa,@len)=-1 then
        begin
        writeln('accept failed with ',socketerror);
        exit;
        end;
      writeln('connection accepted');
      c:=c+1;
      end;
  until c=2;
  closesocket(sock);

end.

If you run the program and do from a console a
telnet localhost 1234
to connect to the program, it will print 'connection accepted' and close
immediately.

Ludo


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to close TInetServer without except?

silvioprog
In reply to this post by zaher dirkey
2013/5/4 Zaher Dirkey <[hidden email]>

On Sat, May 4, 2013 at 8:47 AM, silvioprog <[hidden email]> wrote:
repeat
  if Socket.CanRead(timeout) then
    begin
    insock:=Socket.Accept;
    if insock<>-1 then
      //start working with insock
    else
      //deal with error
    end;
until ThreadTerminated;

Ludo

Thank you!

If you success, tell us, i must fix my sockets too :)

--
I am using last revision of Lazarus, FPC 2.6 on Windows XP SP3

Best Regards
Zaher Dirkey

Yes:


--
Silvio Clécio
My public projects - github.com/silvioprog

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to close TInetServer without except?

silvioprog
In reply to this post by Ludo Brands
2013/5/4 Ludo Brands <[hidden email]>
On 05/04/2013 05:05 PM, Zaher Dirkey wrote:
>
> On Sat, May 4, 2013 at 5:40 PM, Ludo Brands <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Can you show the code you use? You tested on Windows, linux, Mac, ...?
>
>
> Only on Windows XP
>


This is a small test program that works for me on XP and linux:

program testselect;

{$mode objfpc}{$H+}

uses
  Classes,sockets,
  {$ifdef unix}
  unix,baseunix,unixtype
  {$else}
  ctypes,WinSock2
  {$endif}
  ;

CONST
  LISTENPORT=1234;
var
  sock: cint;
  sa,clsa:sockaddr;
  tv:TTimeVal;
  readfds,writefds,exceptfds:tfdset;
  c: Integer;
  res: cint;
  len: tsocklen;
  one: Integer;
begin
  sock:=fpsocket(AF_INET, SOCK_STREAM, 0);
  if sock=-1 then
    begin
    writeln('socket failed with ',socketerror);
    exit;
    end;
  one:=1;
  if fpsetsockopt(sock, SOL_SOCKET, SO_REUSEADDR, @one, sizeof(one))=-1 then
    begin
    writeln('setsockopt failed with ',socketerror);
    exit;
    end;
  fillchar(sa,sizeof(sa),0);
  sa.sin_port:=htons(LISTENPORT);
  sa.sin_family:=AF_INET;
  sa.sin_addr.s_addr:= INADDR_ANY;
  if fpbind(sock,@sa,sizeof(sa))=-1 then
    begin
    writeln('bind failed with ',socketerror);
    exit;
    end;
  if fplisten(sock,10)=-1 then
    begin
    writeln('listen failed with ',socketerror);
    exit;
    end;
  c:=1;
  repeat
    tv.tv_sec:=1;
    tv.tv_usec:=0;
    {$ifdef unix}
    fpFD_ZERO(readfds);
    fpFD_ZERO(writefds);
    fpFD_ZERO(exceptfds);
    fpFD_SET(sock,readfds);
    res:=fpselect(sock+1,@readfds,@writefds,@exceptfds,@tv);
    if (res=-1) and (socketerror<>ESYSEINTR) then
        begin
        writeln('select failed with ',socketerror);
        exit;
        end;
    if (res>0) and (fpFD_ISSET(sock,readfds)<>0) then
      begin
    {$else}
    FD_ZERO(readfds);
    FD_ZERO(writefds);
    FD_ZERO(exceptfds);
    FD_SET(sock,readfds);
    res:=select(sock+1,@readfds,@writefds,@exceptfds,@tv);
    if (res=-1) and (socketerror<>WSAEINTR) then
       begin
       writeln('select failed with ',socketerror);
       exit;
       end;
    if (res>0) and (FD_ISSET(sock,readfds)) then
      begin
    {$endif}
      fillchar(clsa,sizeof(clsa),0);
      len:=sizeof(clsa);
      if fpaccept(sock,@clsa,@len)=-1 then
        begin
        writeln('accept failed with ',socketerror);
        exit;
        end;
      writeln('connection accepted');
      c:=c+1;
      end;
  until c=2;
  closesocket(sock);

end.

If you run the program and do from a console a
telnet localhost 1234
to connect to the program, it will print 'connection accepted' and close
immediately.

Ludo

I think you should make a server and client component and send it to the Free Pascal team. :)

--
Silvio Clécio
My public projects - github.com/silvioprog

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to close TInetServer without except?

zaher dirkey
In reply to this post by Ludo Brands
Hmm there is diffrents
Yours
res:=select(sock+1,@readfds,@writefds,@exceptfds,@tv);
Mine
c := WinSock2.select(0, PSetRead, PSetWrite, nil, @TimeVal);

0 here in mine, in yours sock+1 (FHandle+1 in mine).
I will take more testing.


On Sat, May 4, 2013 at 8:01 PM, Ludo Brands <[hidden email]> wrote:
On 05/04/2013 05:05 PM, Zaher Dirkey wrote:
>
> On Sat, May 4, 2013 at 5:40 PM, Ludo Brands <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Can you show the code you use? You tested on Windows, linux, Mac, ...?
>
>
> ​Only on Windows XP
>


This is a small test program that works for me on XP and linux:

program testselect;

{$mode objfpc}{$H+}

uses
  Classes,sockets,
  {$ifdef unix}
  unix,baseunix,unixtype
  {$else}
  ctypes,WinSock2
  {$endif}
  ;

CONST
  LISTENPORT=1234;
var
  sock: cint;
  sa,clsa:sockaddr;
  tv:TTimeVal;
  readfds,writefds,exceptfds:tfdset;
  c: Integer;
  res: cint;
  len: tsocklen;
  one: Integer;
begin
  sock:=fpsocket(AF_INET, SOCK_STREAM, 0);
  if sock=-1 then
    begin
    writeln('socket failed with ',socketerror);
    exit;
    end;
  one:=1;
  if fpsetsockopt(sock, SOL_SOCKET, SO_REUSEADDR, @one, sizeof(one))=-1 then
    begin
    writeln('setsockopt failed with ',socketerror);
    exit;
    end;
  fillchar(sa,sizeof(sa),0);
  sa.sin_port:=htons(LISTENPORT);
  sa.sin_family:=AF_INET;
  sa.sin_addr.s_addr:= INADDR_ANY;
  if fpbind(sock,@sa,sizeof(sa))=-1 then
    begin
    writeln('bind failed with ',socketerror);
    exit;
    end;
  if fplisten(sock,10)=-1 then
    begin
    writeln('listen failed with ',socketerror);
    exit;
    end;
  c:=1;
  repeat
    tv.tv_sec:=1;
    tv.tv_usec:=0;
    {$ifdef unix}
    fpFD_ZERO(readfds);
    fpFD_ZERO(writefds);
    fpFD_ZERO(exceptfds);
    fpFD_SET(sock,readfds);
    res:=fpselect(sock+1,@readfds,@writefds,@exceptfds,@tv);
    if (res=-1) and (socketerror<>ESYSEINTR) then
        begin
        writeln('select failed with ',socketerror);
        exit;
        end;
    if (res>0) and (fpFD_ISSET(sock,readfds)<>0) then
      begin
    {$else}
    FD_ZERO(readfds);
    FD_ZERO(writefds);
    FD_ZERO(exceptfds);
    FD_SET(sock,readfds);
    res:=select(sock+1,@readfds,@writefds,@exceptfds,@tv);
    if (res=-1) and (socketerror<>WSAEINTR) then
       begin
       writeln('select failed with ',socketerror);
       exit;
       end;
    if (res>0) and (FD_ISSET(sock,readfds)) then
      begin
    {$endif}
      fillchar(clsa,sizeof(clsa),0);
      len:=sizeof(clsa);
      if fpaccept(sock,@clsa,@len)=-1 then
        begin
        writeln('accept failed with ',socketerror);
        exit;
        end;
      writeln('connection accepted');
      c:=c+1;
      end;
  until c=2;
  closesocket(sock);

end.

If you run the program and do from a console a
telnet localhost 1234
to connect to the program, it will print 'connection accepted' and close
immediately.

Ludo


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal



--
I am using last revision of Lazarus, FPC 2.6 on Windows XP SP3

Best Regards
Zaher Dirkey

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to close TInetServer without except?

Ludo Brands
On 05/04/2013 08:00 PM, Zaher Dirkey wrote:

> Hmm there is diffrents
> Yours
> res:=select(sock+1,@readfds,@writefds,@exceptfds,@tv);
> Mine
> c := WinSock2.select(0, PSetRead, PSetWrite, nil, @TimeVal);
>
> 0 here in mine, in yours sock+1 (FHandle+1 in mine).
> I will take more testing.
>
>

According to
http://msdn.microsoft.com/en-us/library/windows/desktop/ms740141(v=vs.85).aspx
:
"nfds [in] Ignored. The nfds parameter is included only for
compatibility with Berkeley sockets."

I wrote the code for linux and then "ported" it to windows.

However, in your code you do
if (c = 0) or (c = SOCKET_ERROR) then
  begin
    Error;

which is not correct. c=0 is the result of select returning after a
timeout. It is not an error.
The fact that
   if Socket.Select(10000, slRead) = erNone then
is blocked forever​ is not normal. It should at least return after 10
seconds.



Ludo



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
123