fpSelect on TCP socket lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- iwilson · 2012-01-11 19:33 Hi, I have a multi-threaded program, one thread has a socket which receives connections and then passes the new socket onto a new thread. It can receive fine (blocking recv), however using fpSelect infront of it as usual does not seem to work (always returns -1), even though I know there is a message there and I receive one with the line removed. Here is the code for the socket thread (not the accepting thread) Code: [Select]unit socket; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, Sockets, BaseUnix, UnixType; type   TSocket = Class (TThread)   private     FSocket      : LongInt;     TestInt      : Integer;     MTFD         : TFDSet;   protected     procedure Execute; Override;   public     constructor Create(Socket : LongInt; ClientAddr : SockAddr_In);   end; implementation    constructor TSocket.Create(Socket : LongInt; ClientAddr : SockAddr_In);    begin      FSocket := Socket;      fpFD_Zero(MTFD);      TestInt := fpFD_Set(FSocket, MTFD);      inherited Create(False);    end;    procedure TSocket.Execute;    var      Timeout  : TTimeVal;      RTFD     : TFDSet;      Bytes_In : Array[0..255] of byte;      Len      : Word;    begin      while(NOT Terminated) do      begin        RTFD := MTFD;        Timeout.tv_usec := 100;        if(fpSelect(FSocket + 1,@RTFD,nil,nil,@Timeout) > 0) then        begin          Len := fpRecv(FSocket,@Bytes_In,256,0);        end;        Sleep(1);      end;    end; end. Any direction would  be helpful, thanks. ---------------------------------------------------------------------- iwilson · 2012-01-11 19:38 I looked at this all day and after finally posting I changed @Timeout to -1 and all works... ---------------------------------------------------------------------- marcov · 2012-01-12 11:17 Maybe not setting timeout.tv_sec was the original problem? Stack values are not initialized?