usb: native_posix: Use non-blocking socket

Use non-blocking socket for native_posix to allow other processes to
run.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
This commit is contained in:
Andrei Emeltchenko 2018-09-12 12:35:33 +03:00 committed by Anas Nashif
commit 03b7d9f59d

View file

@ -313,7 +313,7 @@ void usbip_start(void)
posix_exit(EXIT_FAILURE); posix_exit(EXIT_FAILURE);
} }
listenfd = socket(PF_INET, SOCK_STREAM, 0); listenfd = socket(PF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
if (listenfd < 0) { if (listenfd < 0) {
SYS_LOG_ERR("socket() failed: %s", strerror(errno)); SYS_LOG_ERR("socket() failed: %s", strerror(errno));
posix_exit(EXIT_FAILURE); posix_exit(EXIT_FAILURE);
@ -346,6 +346,13 @@ void usbip_start(void)
connfd = accept(listenfd, (struct sockaddr *)&client_addr, connfd = accept(listenfd, (struct sockaddr *)&client_addr,
&client_addr_len); &client_addr_len);
if (connfd < 0) { if (connfd < 0) {
if (errno == EAGAIN || errno == EWOULDBLOCK) {
/* Non-blocking accept */
k_sleep(100);
continue;
}
SYS_LOG_ERR("accept() failed: %s", strerror(errno)); SYS_LOG_ERR("accept() failed: %s", strerror(errno));
posix_exit(EXIT_FAILURE); posix_exit(EXIT_FAILURE);
} }