Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Blocking Socket



On 14 May 2004, at 2:14 PM, Dario wrote:

I have a socket problem. even if using this

fcntl(sock,F_SETFD,O_NONBLOCK);

You want F_SETFL. F_SETFD is only used for the close-on-exec bit.

If you check the error return, you can spot errors like this more easily.

/** Type of error return; used by error_wrap */
enum error_return_type {
DIRECT, /**< pthread functions; return 0 or Exxx */
NEGATIVE, /**< sigsafe functions; return >= 0 or -Exxx */
ERRNO /**< old-school functions; return >= 0 or -1, Exxx in errno */
};

/** Aborts if retval/type/errno indicate error. */
int error_wrap(int retval, const char *fname, enum error_return_type type);

int oldflags;
error_wrap(oldflags = fcntl(sock, F_GETFL), "fcntl(F_GETFL)", ERRNO);
error_wrap(fcntl(sock, F_SETFL, oldflags | O_NONBLOCK), "fcntl(F_SETFL)", ERRNO);

The socket blocks on this call

ret = ::read(fd, &data[ctr], 1 );

Are you sure fd and sock are the same descriptor?

Scott
_______________________________________________
darwin-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-development
Do not post admin requests to the list. They will be ignored.


References: 
 >Blocking Socket (From: Dario <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.