| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | sockets with emx/gcc & warp |
Hello Thomas! Replying to a message of Thomas Seeling to Brett Maxfield: BM>> I was wondering if anybody is familiar with building tcp/ip servers BM>> with warp, specifically using the emx/bsd programming interface. TS> That's correct, you call bind(), listen() and accept() in a server, TS> and depending on the settings for listen, either you accept a TS> connection from a certain ip address or from any address. You can 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. I am not yet fully familiar with threads.. but 'not theadsafe' would mean non-reeentrant among threads of a single task? This would be ok as each thread would have be given a socket fd, and a hostname or maybe a struct with any miscelleneous connection info by it's controlling task. BM>> 7. spawn or fork a process to handle that connection TS> You should fire up a thread instead. Avoid fork() whereever possible. TS> This is a kludge with OS/2 and very inefficient. Use it only when TS> porting Unix pieces to get it run quickly, then think about how to TS> replace the fork() by threads. Most likely i will have a server process, with each connection having a thread which is given the socket fd for that connection. The thread could then exit asynchronously when the connection died. It would then be responsible for freeing the passed socket and ending it's thread, when the connection was complete. TS> These are cuts from my www server. You have to fill in some gaps TS> (proxy, caching, security :-) ), but it definitely works (then). TS> tid=_beginthread(handlereq,NULL,STACK,NULL); I will most likely need to read up on begin/end thread.. but your code looks like it will solve most of my problems :) The only other thing is, how does the thread then control the status of the connection, ie. detect when the connection has been lost, or if it decides that the connection has to be closed. If the main task recieved a terminating signal, it would need to be able to close all it's threads which would (hopefully) be able to remove any resources that they were using when they got the signal. I have recently found the online docs in an old devcon (volume 7) which documents the socket calls in quite a bit of detail. The only problem is that the examples are single-threaded. I really appreciate your assistance.. Cheers Brett --- FleetStreet 1.14 NR* Origin: Space Now! BBS - 4 CD-ROMS, 5 Gigabytes Online! (3:640/374) 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: 640/374 201 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™.