Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bd99b2e

Browse files
author
bluenet13
committed
netdpsock_send is nonblocking function, shall check egain
1 parent 586aeb8 commit bd99b2e

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

src/event/modules/ngx_opendp_module.c

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,16 +359,52 @@ int ioctl(int fd, int request, void *p)
359359
ssize_t writev(int fd, const struct iovec *iov, int iovcnt)
360360
{
361361
ssize_t rc, i, n;
362+
int nwrite, data_size;
363+
char *buf;
362364

363-
if (fd & (1 << ODP_FD_BITS)) {
365+
if (fd & (1 << ODP_FD_BITS))
366+
{
364367
fd &= ~(1 << ODP_FD_BITS);
365368
rc = 0;
366-
for (i = 0; i != iovcnt; ++i) {
367-
n = netdpsock_send(fd, iov[i].iov_base, iov[i].iov_len, 0);
368-
if (n <= 0) return n;
369-
rc += n;
369+
for (i = 0; i != iovcnt; ++i)
370+
{
371+
data_size = iov[i].iov_len;
372+
buf = iov[i].iov_base;
373+
n = data_size;
374+
while (n > 0)
375+
{
376+
nwrite = netdpsock_send(fd, buf + data_size - n, n, 0);
377+
378+
if(nwrite<=0)
379+
{
380+
if(errno==NETDP_EAGAIN)
381+
{
382+
usleep(200); /* no space in netdp stack */
383+
continue;
384+
}
385+
else
386+
{
387+
printf("write error: errno = %d, strerror = %s \n" , errno, strerror(errno));
388+
return(nwrite);
389+
}
390+
}
391+
392+
if (nwrite < n)
393+
{
394+
usleep(200);/* no space in netdp stack */
395+
}
396+
n -= nwrite;
397+
398+
}
399+
400+
if (nwrite <= 0)
401+
return nwrite;
402+
403+
rc += data_size;
370404
}
371-
} else {
405+
}
406+
else
407+
{
372408
rc = real_writev(fd, iov, iovcnt);
373409
}
374410
return rc;

0 commit comments

Comments
 (0)