gdb_proto/sockets: gdb_peek() shouldn't fail on poll timeout.
This commit is contained in:
parent
bc69c3d065
commit
8ffb7551a6
13
gdb_proto.c
13
gdb_proto.c
|
@ -50,10 +50,15 @@ void gdb_printf(struct gdb_data *data, const char *fmt, ...)
|
||||||
data->outlen += len;
|
data->outlen += len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Returns -1 for error, 0 for timeout, >0 if data received. */
|
||||||
static int gdb_read(struct gdb_data *data, int timeout_ms)
|
static int gdb_read(struct gdb_data *data, int timeout_ms)
|
||||||
{
|
{
|
||||||
|
int was_timeout;
|
||||||
int len = sockets_recv(data->sock, data->xbuf, sizeof(data->xbuf), 0,
|
int len = sockets_recv(data->sock, data->xbuf, sizeof(data->xbuf), 0,
|
||||||
timeout_ms);
|
timeout_ms, &was_timeout);
|
||||||
|
|
||||||
|
if (was_timeout)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
data->error = 1;
|
data->error = 1;
|
||||||
|
@ -74,8 +79,8 @@ static int gdb_read(struct gdb_data *data, int timeout_ms)
|
||||||
|
|
||||||
int gdb_peek(struct gdb_data *data, int timeout_ms)
|
int gdb_peek(struct gdb_data *data, int timeout_ms)
|
||||||
{
|
{
|
||||||
if (data->head == data->tail && gdb_read(data, timeout_ms) < 0)
|
if (data->head == data->tail)
|
||||||
return -1;
|
return gdb_read(data, timeout_ms);
|
||||||
|
|
||||||
return data->head != data->tail;
|
return data->head != data->tail;
|
||||||
}
|
}
|
||||||
|
@ -85,7 +90,7 @@ int gdb_getc(struct gdb_data *data)
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
/* If the buffer is empty, receive some more data */
|
/* If the buffer is empty, receive some more data */
|
||||||
if (data->head == data->tail && gdb_read(data, -1) < 0)
|
if (data->head == data->tail && gdb_read(data, -1) <= 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
c = data->xbuf[data->head];
|
c = data->xbuf[data->head];
|
||||||
|
|
10
sockets.c
10
sockets.c
|
@ -120,7 +120,7 @@ ssize_t sockets_send(SOCKET s, const void *buf, size_t len, int flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t sockets_recv(SOCKET s, void *buf, size_t len, int flags,
|
ssize_t sockets_recv(SOCKET s, void *buf, size_t len, int flags,
|
||||||
int timeout_ms)
|
int timeout_ms, int *was_timeout)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
DWORD to_arg = (timeout_ms >= 0) ? timeout_ms : INFINITE;
|
DWORD to_arg = (timeout_ms >= 0) ? timeout_ms : INFINITE;
|
||||||
|
@ -131,6 +131,9 @@ ssize_t sockets_recv(SOCKET s, void *buf, size_t len, int flags,
|
||||||
ret = recv(s, buf, len, flags);
|
ret = recv(s, buf, len, flags);
|
||||||
} while (ret < 0 && !sockets_wait(to_arg));
|
} while (ret < 0 && !sockets_wait(to_arg));
|
||||||
|
|
||||||
|
if (was_timeout)
|
||||||
|
*was_timeout = (ret < 0 && (error_save == WAIT_TIMEOUT));
|
||||||
|
|
||||||
sockets_end(s);
|
sockets_end(s);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -151,7 +154,7 @@ ssize_t sockets_send(SOCKET s, const void *buf, size_t len, int flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t sockets_recv(SOCKET s, void *buf, size_t buf_len, int flags,
|
ssize_t sockets_recv(SOCKET s, void *buf, size_t buf_len, int flags,
|
||||||
int timeout_ms)
|
int timeout_ms, int *was_timeout)
|
||||||
{
|
{
|
||||||
fd_set r;
|
fd_set r;
|
||||||
struct timeval to = {
|
struct timeval to = {
|
||||||
|
@ -166,6 +169,9 @@ ssize_t sockets_recv(SOCKET s, void *buf, size_t buf_len, int flags,
|
||||||
timeout_ms < 0 ? NULL : &to) < 0)
|
timeout_ms < 0 ? NULL : &to) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
if (was_timeout)
|
||||||
|
*was_timeout = !FD_ISSET(s, &r);
|
||||||
|
|
||||||
if (!FD_ISSET(s, &r)) {
|
if (!FD_ISSET(s, &r)) {
|
||||||
errno = ETIMEDOUT;
|
errno = ETIMEDOUT;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -48,6 +48,6 @@ SOCKET sockets_accept(SOCKET s, struct sockaddr *addr, socklen_t *addrlen);
|
||||||
int sockets_connect(SOCKET s, const struct sockaddr *addr, socklen_t addrlen);
|
int sockets_connect(SOCKET s, const struct sockaddr *addr, socklen_t addrlen);
|
||||||
ssize_t sockets_send(SOCKET s, const void *buf, size_t len, int flags);
|
ssize_t sockets_send(SOCKET s, const void *buf, size_t len, int flags);
|
||||||
ssize_t sockets_recv(SOCKET s, void *buf, size_t len, int flags,
|
ssize_t sockets_recv(SOCKET s, void *buf, size_t len, int flags,
|
||||||
int timeout_ms);
|
int timeout_ms, int *was_timeout);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue