Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2003-06

Sockets Problem; accept - eof

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Ivan Petrov

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.