On 12/17/2010 09:06 AM, Sebastian Dransfeld wrote:
On 12/17/2010 05:30 AM, Mike McCormack wrote:
On 12/17/2010 05:41 AM, Sebastian Dransfeld wrote:

             num = read(svr->fd, buf, sizeof(buf));
-        if ((num>     0) || (errno == EAGAIN))
+        if ((num>= 0) || (errno == EAGAIN))
               lost_server = EINA_FALSE;

Sure this is right? a ret 0 an errno != EAGAIN is probably a lost server.

0 is a successful return, so errno is not set in that case.

The above fix looks correct to me.

Depends on how the main loop works. We had this discussion a while ago,
and the result was:

http://trac.enlightenment.org/e/changeset/54209/trunk/ecore/src/lib/ecore_con/ecore_con.c


And:

http://stackoverflow.com/questions/2416944/can-read-function-on-a-connected-socket-return-zero-bytes

So 0 is _not_ a valid return value on a tcp socket.

S.
#include <stdio.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netdb.h>
#include <string.h>

int
main(void)
{
	int s;
	struct sockaddr_in socket_addr;
	struct hostent *he;
	struct linger lin;

	s = socket(AF_INET, SOCK_STREAM, 0);

#if 0
	/* if linger is set to 0, we will get ECONNRESET */
	lin.l_onoff = 1;
	lin.l_linger = 0;
	setsockopt(s, SOL_SOCKET, SO_LINGER, &lin, sizeof(lin));
#endif

	socket_addr.sin_family = AF_INET;
	socket_addr.sin_port = htons(1234);
	he = gethostbyname("localhost");
	memcpy (&socket_addr.sin_addr, he->h_addr, sizeof (struct in_addr));
	connect(s, (struct sockaddr *)&socket_addr, sizeof (struct sockaddr_in));
	close(s);
	sleep(1);
	return 0;
}
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <sys/epoll.h>

#define MAX_EVENTS 10

int
main(void)
{
	int ss, s, ret;
	struct sockaddr_in socket_addr;
	struct sockaddr_in socket_in;
	socklen_t len;
	struct linger lin;
	char data[1024];
	struct epoll_event ev, events[MAX_EVENTS];
	int nfds, epollfd;

	ss = socket(AF_INET, SOCK_STREAM, 0);

	lin.l_onoff = 1;
	lin.l_linger = 0;
	setsockopt(ss, SOL_SOCKET, SO_LINGER, &lin, sizeof(lin));

	socket_addr.sin_family = AF_INET;
	socket_addr.sin_port = htons(1234);
	socket_addr.sin_addr.s_addr = htonl(INADDR_ANY);
	bind(ss, (struct sockaddr *) &socket_addr, sizeof(struct sockaddr_in));

	listen(ss, 1);

	s = accept(ss, (struct sockaddr *) &socket_in, &len);
	setsockopt(s, SOL_SOCKET, SO_LINGER, &lin, sizeof(lin));
	fcntl(s, F_SETFL, O_NONBLOCK);

	epollfd = epoll_create(10);
	ev.events = EPOLLIN;
	ev.data.fd = s;
	epoll_ctl(epollfd, EPOLL_CTL_ADD, s, &ev);
	nfds = epoll_wait(epollfd, events, MAX_EVENTS, -1);

	do {
		ret = read(s, data, sizeof(data));
		printf("a: %d\n", ret);
		if (ret < 0)
		{
			printf("ret = %d, errno = %d\n", ret, errno);
			perror("a");
		}
	} while (ret >= 0);
	close(s);
	close(ss);
	return 0;
}
------------------------------------------------------------------------------
Lotusphere 2011
Register now for Lotusphere 2011 and learn how
to connect the dots, take your collaborative environment
to the next level, and enter the era of Social Business.
http://p.sf.net/sfu/lotusphere-d2d
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to