If you make your server app multi-threaded, you wont have to mess with
select() at all.

Exactly how you structure your app will depend on many things like are
the connections persistent or "connect, do a single transaction,

If they are persistent, what kind of volume?

Answers to these questions will help you determine your threading
model.  Eg: Simply allocate a thread to service each client or use
"worker" threads.  Allocating a thread per client works well when a)
number of concurrent clients is small -or-b) volume from each client is
high -or- c) you want to keep things simple and performance isn't an

Regardless of the thread model you use, the socket logic is fairly

In the main listener thread:

1) bind()
2) listen()             // wait for a new connection request
3) accept()     // get the new connect request
4) givedescriptor()     //set up to pass the socket to a thread
5)                      // depending on thread model, figure out what thread to 
send the
socket over to
6) Go back up and do your listen() again and wait for next connect

Then in the processing threads:

1) takedescriptor()
2) now act like the rest of the world doesn't exist.  Use blocking
send/receives etc.

If you are dealing with a lot of clients, the above logic will have to
be modified somewhat, but the concept is similar.

I use give/takedescriptor because when I wrote the socket my server
that runs on the as/400, "threads" didn't exist in os/400.  So I had to
use jobs instead of threads and the give/takedescriptor was the only
way to pass the sockets between jobs.

In the PC world, there are much easier ways to pass a socket between
threads and if they are available for you to use on the AS/400, you
should probably use them.

Bob Crothers
Cornerstone Communications

-----Original Message-----
From: []On
Behalf Of Srikanth_D
Sent: Friday, May 31, 2002 4:34 AM
Subject: [C400-L] select()

hi all,

i am a little confused on how to use select() in a socket program. here
the deal.

client connects to a server to accomplish a transaction, let us say
balance enquiry. right now my code blocks on a send() and recv(), for
client send()s the account number and blocks on a recv() to get the
of the account. i would like to eliminate these blocking. i think using
select() would be the choice for that, but what would be the basis to
values to the struct timeval which is the fifth parameter in select().
can i
use select() in a multithreaded environment. for complex transactions
fund transfer between two accounts) i have various send() and recv(),
do i
need to code select() before each send() and recv().

please help me on this.

thanks in advance.
-srikanth d
This email (including any attachments) is intended for the sole use of
intended recipient/s and may contain material that is CONFIDENTIAL AND
PRIVATE COMPANY INFORMATION. Any review or reliance by others or
copying or
distribution or forwarding of any or all of the contents in this
message is
STRICTLY PROHIBITED. If you are not the intended recipient, please
the sender by email and delete all copies; your cooperation in this
is appreciated.
This is the C programming iSeries / AS400 (C400-L) mailing list
To post a message email:
To subscribe, unsubscribe, or change list options,
or email:
Before posting, please take a moment to review the archives

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2020 by and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].