[fpc-pascal]Sockets Problem; accept - eof

Ivan Petrov jhs at bse.bg
Thu Jun 12 22:11:54 CEST 2003


Hello!

I use the following programfor testing, mostly as in examples.
And I can not understand why calling eof(sin) after the ACCEPT,
blocks until something arrived in sin ?!?!?
The socket is (I think so) is changed to non-blocking.

Program alabala;
uses Linux, Sockets, Crt, SysUtils;
const port : word = 99;
var Ad        : TInetSockAddr;
    S         : Longint;
    sin, sout : text;

procedure Perror(const S:string);
begin
  writeln(S, SocketError);
  halt(100);
end;

Begin
  Ad.family := AF_INET;
  Ad.port := swap(port);
  Ad.addr :=  0;
  S := Socket(AF_INET, SOCK_STREAM, 0);
  if SocketError <> 0 then Perror('Server: Socket: ');
  if not Bind(S, Ad, sizeof(Ad)) then Perror('Server: Bind: ');
  if not Listen(S, 1) then  Perror('Server: Listen: ');
  Writeln('Waiting for connecttion on port:', swap(Ad.port));
{ any suggestions about next dirty work - more clean, more pascalish, etc. }
// long live to linux man pages !!!
  fcntl(S,F_SETFL,OPEN_NONBLOCK); // MAKE SOCKET NON-BLOCKING

  repeat   // wait for incoming connection
    write('.');
    delay(200);
  until accept(S, Ad, Sin, Sout);
  reset(sin);

  writeln(eof(sin)); // this blocks the program, if no data pending in sin.
  shutdown(S, 2);  //and after some data comes, we obviously get "FALSE"
End.			// and program continues.





More information about the fpc-pascal mailing list