On 4/7/2013 9:06 AM, marco atzeri wrote:
On 4/6/2013 11:10 PM, Corinna Vinschen wrote:
What is the original code doing?
Corinna
I think the problem in on recv definition.
my code is (with all added printf) :
--------------------------------------------------------
static void
evsig_cb(evutil_socket_t fd, short what, void *arg)
{
static char signals[1024];
ev_ssize_t n;
int i;
int ncaught[NSIG];
struct event_base *base;
base = arg;
memset(&ncaught, 0, sizeof(ncaught));
while (1) {
n = recv(fd, signals, sizeof(signals), 0);
printf("recv %li \n",n);
fflush(stdout);
if (n == -1) {
printf("n==-1 %li \n",n);
fflush(stdout);
int err = evutil_socket_geterror(fd);
printf("err %i \n",err);
fflush(stdout);
if (! EVUTIL_ERR_RW_RETRIABLE(err))
event_sock_err(1, fd, "%s: recv",
__func__);
printf("func %s \n",__func__);
fflush(stdout);
break;
} else if (n==0) {
/* XXX warn? */
break;
} else {
printf("before for n %li \n",n);
fflush(stdout);
for (i = 0; i < n; ++i) {
ev_uint8_t sig = signals[i];
if (sig < NSIG)
ncaught[sig]++;
}
}
}
-----------------------------------------------------
and the relevant output is
----------------------------------------------------
recv 2
before for n 2
recv 4294967295
before for n 4294967295
[MARCOATZERI:03904] *** Process received signal ***
[MARCOATZERI:03904] Signal: Segmentation fault (11)
-----------------------------------------------------
so recv is returning 2^32-1 instead of the expected -1
on winsup/cygwin/net.cc is defined as function returning int
-------------------------------------------------------
/* exported as recv: standards? */
extern "C" int
cygwin_recv (int fd, void *buf, size_t len, int flags)
{
int res;
fhandler_socket *fh = get (fd);
myfault efault;
if (efault.faulted (EFAULT) || !fh)
res = -1;
-------------------------------------------------------
while on sys/socket.h
ssize_t recv (int, void *__buff, size_t __len, int __flags);
on POSIX
http://pubs.opengroup.org/onlinepubs/009695399/functions/recv.html
(and also
newlib/libc/sys/linux/net/recv.c return ssize_t)
while:
sizeof(int) = 4
sizeof(ssize_t) = 8
Regards
Marco