curl-library
Re: connect() select() poll() checking against -1 return values
Date: Wed, 19 Nov 2008 14:47:45 -0800
Got this working finally, but I have to say keeping the code segments
separated from the macros and the cell OS calls required some thought.
Also to fix some warnings I had to do some semi-strange double macro'ing
for CellOS functions that weren't named the same as the normal "socket"
implementations.
Sample from config-ps3.h
#define connect(a,b,c) cell_connect(a,b,c)
#define recv(a,b,c,d) cell_recv(a,b,c,d)
#define send(a,b,c,d) cell_send(a,b,c,d)
/* have to do this double macro on cell for functions that aren't named the
same as the macro's */
/* or else you will get warnings at build time. This is because these
macros will actually change */
/* the function declarations in the CellOS includes, so in <sys/poll.h> int
socketpoll() actually */
/* becomes int cell_poll(). This seems like it would cause things to break,
but the linker appears */
/* to be smart enough to keep this from being an issue */
#define poll(a,b,c) socketpoll(a,b,c)
#define socketpoll(a,b,c) cell_poll(a,b,c)
#define select(a,b,c,d,e) socketselect(a,b,c,d,e)
#define socketselect(a,b,c,d,e) cell_select(a,b,c,d,e)
What I found was that the macro's are actually changing the CellOS system
includes during preprocessing, which makes sense, but surprises me that the
linker is smart enough to sort out the difference. The issue arose that for
the two oddly names CellOS functions socketpoll and socketselect it would
give me a compiler warning that "cell_poll" and "cell_select" were
implicitly defined, though it would build and run fine.
Then as you stated I simply added a cellos.c (no header file) to the
curllib project, with implementations of my "cell_" versions of each
function that return -1 on errors to keep in line with your POSIX -like
implementation.
Anyway, I was able to remove all my horrific #ifdefs around checks for -1
return values now, thanks for the push in this direction, it was harder
than I expected but seems to be the right way to implement it.
--Jeff Curley
Sony Computer Entertainment America
Senior Programmer
(858) 824-5692
Jeff
Curley/SDPD/SCEA@
Playstation To
Sent by: libcurl development
curl-library-boun <curl-library_at_cool.haxx.se>
ces_at_cool.haxx.se cc
Subject
11/19/2008 12:28 Re: connect() select() poll()
PM checking against -1 return values
Please respond to
libcurl
development
<curl-library_at_coo
l.haxx.se>
yeah I considered doing exactly that yesterday but I ran into issues with
having a macro named "connect" and pulling in the CellOS function header
for "connect" I wasn't being careful though to keep the includes separated,
so I think you are totally right and I'll give it another shot today.
Thanks Dan :)
--Jeff Curley
Sony Computer Entertainment America
Senior Programmer
(858) 824-5692
Daniel Stenberg
<daniel_at_haxx.se>
Sent by: To
curl-library-boun libcurl development
ces_at_cool.haxx.se <curl-library_at_cool.haxx.se>
cc
11/19/2008 05:34 Subject
AM Re: connect() select() poll()
checking against -1 return values
Please respond to
libcurl
development
<curl-library_at_coo
l.haxx.se>
On Tue, 18 Nov 2008, Jeff_Curley_at_playstation.sony.com wrote:
> If libcurl had chosen to mask away the socket implementation calls such
as
> using _connect, _recv, _send, etc., I could have macro'd my changes away
> easily in my config-ps3.h file.
Right, but libcurl has taken the opposite approach and thus _you_ can do
the
masking away of your system's internals! We've deliberately assumed a
POSIX-like API and that implies -1 for errors.
You should be able to do something similar to this:
/* in a header libcurl uses: */
#define connect(x,y,z) my_connect(x,y,z)
/* in source code that libcurl links with: */
int my_connect(int socket, const struct sockaddr *address,
socklen_t address_len)
{
int rc = (connect)(socket, address, address_len);
if(rc < 0) {
errno = rc;
rc = -1;
}
return rc;
}
> But the good news is, it works on PS3 with minimal changes, which is a
> testament to this communities hard work.
Cool news, thanks for letting us know!
-- / daniel.haxx.seReceived on 2008-11-19