TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Brett Maxfield
from: Thomas Seeling
date: 1996-07-10 23:53:48
subject: sockets with emx/gcc & warp

Hallo, Brett!

*** Am Dienstag 09. Juli 1996 um 14:07 schrieb Brett Maxfield an Thomas Seeling:

 TS>> find out the hostname, but you should be aware that gethostbyaddr is
 TS>> not threadsafe from my experience (tcp/ip 2.0 and un64092). Therefore
 TS>> a mutex semaphore should be used to encapsulate the call.

 BM>  I am not yet fully familiar with threads.. but 'not theadsafe' would
 BM>  mean non-reeentrant among threads of a single task? This would be ok as
 BM>  each thread would have be given a socket fd, and a hostname or maybe
 BM>  a struct with any miscelleneous connection info by it's controlling
 BM>  task.
threadsafe means that multiple threads can concurrently call the same
function and be successfull.

This is not the case if the function uses static data structures. A
prominent example is strtok(), as you might know.

gethostbyaddr() suffers from the same problem. You call it and receive a
pointer to static data as return result. As soon as the next call happens,
the data is corrupt in respect to what the first caller expects.

Protect the call with a mutex semaphore, copy the data and then release the
semaphore.

 BM>  Most likely i will have a server process, with each connection having
 BM>  a thread which is given the socket fd for that connection. The thread
 BM>  could then exit asynchronously when the connection died. It would then
 BM>  be responsible for freeing the passed socket and ending it's thread,
 BM>  when the connection was complete.
That's the usual approach.

 BM>  The only other thing is, how does the thread then control the status of
 BM>  the connection, ie. detect when the connection has been lost, or if it
 BM>  decides that the connection has to be closed.
Either you receive a SIG_PIPE, or the read/write call returns with an
return code indicating the problem (rc==-1 and errno set or similar
things).


Tschau...Thomas

--- E3-32/1.11-32/2.50+
* Origin: Die TeX-Box +49-6034-930021 V.34 -930022 ISDN 24h (2:244/1130.42)
SEEN-BY: 50/99 270/101 620/243 625/100 711/401 409 410 413 430 808 809 934
SEEN-BY: 711/955 712/407 515 517 628 713/888 800/1
@PATH: 244/1130 24/999 888 396/1 270/101 712/515 711/808 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.