× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Srikanth,

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,
disconnect"?

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
issue.

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

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
request.

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.

Regards,
Bob Crothers
Cornerstone Communications
http://www.cstoneindy.com




-----Original Message-----
From: c400-l-admin@midrange.com [mailto:c400-l-admin@midrange.com]On
Behalf Of Srikanth_D
Sent: Friday, May 31, 2002 4:34 AM
To: c400-l@midrange.com
Subject: [C400-L] select()

hi all,

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

client connects to a server to accomplish a transaction, let us say
account
balance enquiry. right now my code blocks on a send() and recv(), for
e.g.
client send()s the account number and blocks on a recv() to get the
balance
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
set
values to the struct timeval which is the fifth parameter in select().
can i
use select() in a multithreaded environment. for complex transactions
(like
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
the
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
contact
the sender by email and delete all copies; your cooperation in this
regard
is appreciated.
***********************************************************************
***
_______________________________________________
This is the C programming iSeries / AS400 (C400-L) mailing list
To post a message email: C400-L@midrange.com
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/cgi-bin/listinfo/c400-l
or email: C400-L-request@midrange.com
Before posting, please take a moment to review the archives
at http://archive.midrange.com/c400-l.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

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

This mailing list archive is Copyright 1997-2024 by midrange.com 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].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.