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)
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.