@@ -201,6 +201,12 @@ void socket_set_nonblock(int fd)
ioctlsocket(fd, FIONBIO, &opt);
}
+void socket_set_block(int fd)
+{
+ unsigned long opt = 0;
+ ioctlsocket(fd, FIONBIO, &opt);
+}
+
int inet_aton(const char *cp, struct in_addr *ia)
{
uint32_t addr = inet_addr(cp);
@@ -223,6 +229,13 @@ void socket_set_nonblock(int fd)
fcntl(fd, F_SETFL, f | O_NONBLOCK);
}
+void socket_set_block(int fd)
+{
+ int f;
+ f = fcntl(fd, F_GETFL);
+ fcntl(fd, F_SETFL, f & ~O_NONBLOCK);
+}
+
void qemu_set_cloexec(int fd)
{
int f;
@@ -2092,12 +2092,35 @@ static void tcp_chr_telnet_init(int fd)
send(fd, (char *)buf, 3, 0);
}
-static void socket_set_nodelay(int fd)
+void socket_set_delay(int fd)
+{
+ int val = 0;
+ setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(val));
+}
+
+void socket_set_nodelay(int fd)
{
int val = 1;
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(val));
}
+void socket_set_timeout(int fd, int s)
+{
+ struct timeval tv = {
+ .tv_sec = s,
+ .tv_usec = 0
+ };
+ /* Set socket_timeout */
+ if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO,
+ &tv, sizeof(tv)) < 0) {
+ fprintf(stderr, "failed to set SO_RCVTIMEO\n");
+ }
+ if (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO,
+ &tv, sizeof(tv)) < 0) {
+ fprintf(stderr, "fialed to set SO_SNDTIMEO\n");
+ }
+}
+
static void tcp_chr_accept(void *opaque)
{
CharDriverState *chr = opaque;
@@ -35,6 +35,10 @@ int inet_aton(const char *cp, struct in_addr *ia);
int qemu_socket(int domain, int type, int protocol);
int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
void socket_set_nonblock(int fd);
+void socket_set_block(int fd);
+void socket_set_nodelay(int fd);
+void socket_set_delay(int fd);
+void socket_set_timeout(int fd, int s);
int send_all(int fd, const void *buf, int len1);
/* New, ipv6-ready socket helper functions, see qemu-sockets.c */