2013-07-16 25 views
7

In seguito è la sequenza che sto ottenendoPerché strace mostra EAGAIN (Risorsa temporaneamente non disponibile)

socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 7 

    setsockopt(7, SOL_TCP, TCP_NODELAY, [1], 4) = 0 
    setsockopt(7, SOL_SOCKET, SO_SNDBUF, [32120], 4) = 0 
    getsockopt(7, SOL_SOCKET, SO_SNDBUF, [30064835312], [4]) = 0 
    setsockopt(7, SOL_SOCKET, SO_SNDBUF, [64240], 4) = 0 
    getsockopt(7, SOL_SOCKET, SO_SNDBUF, [30064899552], [4]) = 0 
    stat("/etc/localtime", {st_dev=makedev(8, 1), st_ino=229001, st_mode=S_IFREG|0644, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=8, st_size=265, st_atime=2013/07/15-06:30:03, st_mtime=2012/06/25-23:46:43, st_ctime=2012/06/25-23:46:43}) = 0 
    write(1, "[info 2013/07/16 05:53:24.622210"..., 114) = 114 
    setsockopt(7, SOL_SOCKET, SO_RCVBUF, [32120], 4) = 0 
    getsockopt(7, SOL_SOCKET, SO_RCVBUF, [30064835312], [4]) = 0 
    setsockopt(7, SOL_SOCKET, SO_RCVBUF, [64240], 4) = 0 
    getsockopt(7, SOL_SOCKET, SO_RCVBUF, [30064899552], [4]) = 0 
    fcntl(7, F_GETFL)      = 0x2 (flags O_RDWR) 
    fcntl(7, F_SETFL, O_RDWR|O_NONBLOCK) = 0 
    rt_sigaction(SIGPIPE, {SIG_IGN, [PIPE], SA_RESTORER|SA_RESTART, 0x33b3632920}, {SIG_DFL, [], 0}, 8) = 0 
    fcntl(7, F_GETFL)      = 0x802 (flags O_RDWR|O_NONBLOCK) 
    fcntl(7, F_SETFL, O_RDWR|O_NONBLOCK) = 0 
    connect(7, {sa_family=AF_INET, sin_port=htons(50505), sin_addr=inet_addr("1.2.3.4")}, 16) = -1 EINPROGRESS (Operation now in progress) 
    poll([{fd=7, events=POLLIN|POLLOUT}], 1, 59000) = 1 ([{fd=7, revents=POLLOUT}]) 
    fcntl(7, F_GETFL)      = 0x802 (flags O_RDWR|O_NONBLOCK) 
    fcntl(7, F_SETFL, O_RDWR)    = 0 
    getsockname(7, {sa_family=AF_INET, sin_port=htons(33220), sin_addr=inet_addr("10.112.204.215")}, [16]) = 0 
    fcntl(7, F_GETFL)      = 0x2 (flags O_RDWR) 
    fcntl(7, F_GETFL)      = 0x2 (flags O_RDWR) 
    fcntl(7, F_SETFL, O_RDWR|O_NONBLOCK) = 0 
    write(7, "d\23;\177\377\330\357\1&W\1\\\4\np\314\327\0\0\0\2W\0\rpnq-gst-"..., 103) = 103 
    fcntl(7, F_GETFL)      = 0x802 (flags O_RDWR|O_NONBLOCK) 
    fcntl(7, F_SETFL, O_RDWR)    = 0 
    fcntl(7, F_GETFL)      = 0x2 (flags O_RDWR) 
    fcntl(7, F_GETFL)      = 0x2 (flags O_RDWR) 
    fcntl(7, F_SETFL, O_RDWR|O_NONBLOCK) = 0 
    read(7, 0x9d9f90, 1)     = -1 EAGAIN (Resource temporarily unavailable) 

Perché questa lettura viene sempre chiamato, suppongo che poll dovrebbe svegliarsi solo quando ci sono dati da leggere

risposta

2

poll si è svegliato con revents = POLLOUT, il che significa che il socket è pronto per la scrittura, non pronto per la lettura. Apparentemente il codice non sta controllando questa bandiera e sta provando a leggere comunque.

Questo potrebbe essere intenzionale. Anche se poll non ha detto che il socket è pronto per la lettura, potrebbe essere pronto mentre stava scrivendo. Quindi chiama pronto nel caso in cui qualcosa è apparso. In caso contrario, tornerà in poll per attendere di nuovo. Ciò gli consente di elaborare i dati in entrata più rapidamente, poiché può ricevere una chiamata anziché due.

+0

Grazie a @Barmar, sto usando la libreria ACE C++, speravo che gestissero questo – Avinash

+0

causando un problema? – Barmar

+0

Ho lamentato che 'recv' sta consumando una CPU elevata, quindi stavo cercando nella direzione – Avinash