Sign in Join

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

Mailing lists / fpc-pascal / 2003-09

Nonblocking socket - end of socket

6 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

Balázs Csaba

I use non-blocking socket (after initialization i used the fcntl function). Accept does not waiting for client connection, so i need not use threads, I can make it in the main thread.
How can I be alerted when the client socket closed from the client side? Can I use textfiles as SIN and SOUT? Will the eof(SIN) wait for packet?

Thx 4 help
#Tsch : Balázs Csaba

Michael Van Canneyt
to Balázs Csaba
I use non-blocking socket (after initialization i used the fcntl function). Accept does not waiting for client connection, so i need not use threads, I can make it in the main thread. How can I be alerted when the client socket closed from the client side?

Using select() you can see this, normally.

Can I use textfiles as SIN and SOUT?

Yes.

Will the eof(SIN) wait for packet?

Not if the socket is non-blocking.

Michael.

Georgi Georgiev
to Michael Van Canneyt

--- Michael Van Canneyt
wrote: >

Show quoted text 13 lines
On Tue, 16 Sep 2003, [iso-8859-2] Balázs Csaba wrote: > I use non-blocking socket (after initialization i used the fcntl function). > Accept does not waiting for client connection, so i need not use threads, I > can make it in the main thread. > How can I be alerted when the client socket closed from the client side? Using select() you can see this, normally.

There is another way, if you use file descriptor calls for non-blocked socket:

...
count:=fdRead(socket,data,size);
socket_eof:=(count=0) and (LinuxError=0);
...

=====
Skelet
====== http://skelet.hit.bg

________________________________________________________________________ Want to chat instantly with your online friends? Get the FREE Yahoo! Messenger http://mail.messenger.yahoo.co.uk

Sebastian Günther
to Georgi Georgiev
Show quoted text 7 lines
There is another way, if you use file descriptor calls for non-blocked socket: ... count:=fdRead(socket,data,size); socket_eof:=(count=0) and (LinuxError=0); ...

eeehm normally fdread returns -1 for closed sockets, so you can obmit the LinuxError part and just write:

socket_eof := count <= 0;

This will work both for files (where zero means EOF) and sockets (where -1 means error, such as broken pipe)

- Sebastian

Georgi Georgiev
to Sebastian Günther

--- Sebastian_Günther wrote: >

Show quoted text 20 lines
> There is another way, if you use file descriptor calls > for non-blocked socket: > > ... > count:=fdRead(socket,data,size); > socket_eof:=(count=0) and (LinuxError=0); > ... eeehm normally fdread returns -1 for closed sockets, so you can obmit the LinuxError part and just write: socket_eof := count <= 0; This will work both for files (where zero means EOF) and sockets (where -1 means error, such as broken pipe)

I think that if the socket (or file) is in nonblocking mode,
count may be -1, and LinuxError=11 { Err_TryAgain } means that connection is OK, but there is no incoming data
(input is not finished).

Show quoted text 8 lines
- Sebastian _______________________________________________ fpc-pascal maillist -

http://lists.freepascal.org/mailman/listinfo/fpc-pascal

=====
Skelet
====== http://skelet.hit.bg

________________________________________________________________________ Want to chat instantly with your online friends? Get the FREE Yahoo! Messenger http://mail.messenger.yahoo.co.uk

Sebastian Günther
to Georgi Georgiev
Show quoted text 6 lines
I think that if the socket (or file) is in nonblocking mode, count may be -1, and LinuxError=11 { Err_TryAgain } means that connection is OK, but there is no incoming data (input is not finished).

okay that's right; I assumed that reading or writing is only done after select() indicates that data can be read or written.

- Sebastian