Skip to Content.
Sympa Menu

transport - Re: [transport] API comments

Subject: Transport protocols and bulk file transfer

List archive

Re: [transport] API comments


Chronological Thread 
  • From: Yunhong Gu <>
  • To: stanislav shalunov <>
  • Cc:
  • Subject: Re: [transport] API comments
  • Date: Thu, 24 Feb 2005 23:14:11 -0600 (CST)



see this example:

X_SOCKET s = x_socket(AF_INET, SOCK_STREAM, 0);
if (INVALID_SOCK == s)
printf("error d%\n", x_sockerror(???)");

what socket id can you use here as a parameter of the above x_sockerror(),
since you don't even have a valid socket id yet.

another example is x_select(). The error of x_select() can be meaningless
for any particular sockets, i.e.:
if (-1 == x_select(...))
printf("error d%\n", x_sockerror(???)");

While you can use a special number like -1 to check such error
(e.g., x_sockerror(-1)), but this does not looks good :) and this still
need to be checked right after a socket function is called.

I was not concerning about the additional storage, I just thought if a
parameter is not very useful, adding it may bring possible trouble.

> But in C, ``int ferror(FILE *stream)'', ``int feof(FILE *stream)'' is
> a per-object error checking. The advantage is that is the programmer
> is not sufficiently meticulous about error checking, errors could
> still, sometimes, be caught---with subsequent error checks.

If the programmer does not check the error right after a function call,
they, most likely, will not check it later :)

> What should x_sockerror() return, though? Shall we need a list of
> error codes at some later point, or can we get by with errno.h? (This
> is mostly independent of whether the function takes an argument.)

error code is ok. An integer code is convinient for programming. I am
afraid that for a user level implementation, error codes in errno.h may
not be sufficient.

In addition, a helper function can be used to print text error
information, just like perror.

Gu



Archive powered by MHonArc 2.6.16.

Top of Page