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



The call to sys_errno is also looks to be in the wrong place. It's being
called before any operation and then being checked after the recv.




Kevin Bucknum
Senior Programmer Analyst
MEDDATA/MEDTRON
Tel: 985-893-2550

-----Original Message-----
From: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of
Bradley Stone
Sent: Thursday, September 17, 2015 2:04 PM
To: RPG programming on the IBM i (AS/400 and iSeries)
Subject: Re: Question on socket non block read

select() should be called before the read()/recv() to know if the socket
is ready for the read (or write).

The timeout of 60 seconds seems quite big. This isn't a delay if that's
what you're thinking.

If you specify 60 seconds that means it will wait on the select() for up
to
60 seconds for "readiness" and then error if not. If it's found to be
ready right away, it will pass through without error.

Here's how I do it...

do
select()

if (no error)
read/write to socket
if (error on read/write)
exit
endif
else
exit
endif

enddo

Brad
www.bvstools.com

On Thu, Sep 17, 2015 at 12:42 PM, Jeff Young <jyoung0950@xxxxxxxxx>
wrote:

I have the following code:
// nbrecv(): Receive data on non-blocking socket w/timeout
// using Select()
// sock = (input) socket to receive data from
// buf = (output) buffer to receive into (address of
variable)
// size = (input) size of buffer to send (size of variable)
// secs = (input) seconds to wait before timing out
//
// Returns length received, or -1 upon failure (check errno!)

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
P nbrecv B export
D nbrecv pi 10i 0
D sock 10i 0 value
D buf * value
D size 10i 0 value
D secs 10p 3 value

D readset s like(fdset)
D timeout ds likeds(timeval)
D err s 10i 0 based(p_err)
D rc s 10i 0

/free

p_err = sys_errno();

dow '1';

rc = recv(sock: buf: size: 0);
if (rc <> -1);
return rc;
endif;
if (err <> EWOULDBLOCK);
return rc;
endif;

// -----------------------------------
// Wait until socket is readable
// -----------------------------------

FD_ZERO(readset);
FD_SET(sock: readset);
timeout.tv_sec = %int(secs);
timeout.tv_usec = (secs - timeout.tv_sec) * 1000000;

rc = select( sock+1 // descriptor count
: %addr(readset) // read set
: *null // write set
: *null // exception set
: %addr(timeout) ); // timeout
select;
when rc = 0;
err = ETIME;
return -1;
when rc = -1;
return -1;
endsl;

enddo;
/end-free
P E

I am passing a value of 60 for the wait time.
Is this routine correct?
shouldn't the set of the wait time come first?


Jeff Young
Sr. Programmer Analyst
--
This is the RPG programming on the IBM i (AS/400 and iSeries)
(RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx

To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx Before posting, please take a
moment to review the archives at http://archive.midrange.com/rpg400-l.


--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L)
mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To
subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://archive.midrange.com/rpg400-l.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
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.