mirror of
https://github.com/libretro/RetroArch
synced 2025-02-21 00:40:09 +00:00
Get rid of duplicate function net_http_send
This commit is contained in:
parent
3d7b7f6afa
commit
bd9dd06ddd
@ -46,7 +46,7 @@ bool socket_nonblock(int fd);
|
||||
int socket_select(int nfds, fd_set *readfs, fd_set *writefds,
|
||||
fd_set *errorfds, struct timeval *timeout);
|
||||
|
||||
int socket_send_all_blocking(int fd, const void *data_, size_t size);
|
||||
int socket_send_all_blocking(int fd, const void *data_, size_t size, bool no_signal);
|
||||
|
||||
int socket_receive_all_blocking(int fd, void *data_, size_t size);
|
||||
|
||||
|
@ -109,36 +109,16 @@ error:
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void net_http_send(int fd, bool * error,
|
||||
const char * data, size_t len)
|
||||
{
|
||||
if (*error)
|
||||
return;
|
||||
|
||||
while (len)
|
||||
{
|
||||
ssize_t thislen = send(fd, data, len, MSG_NOSIGNAL);
|
||||
|
||||
if (thislen <= 0)
|
||||
{
|
||||
if (!isagain(thislen))
|
||||
continue;
|
||||
|
||||
*error=true;
|
||||
return;
|
||||
}
|
||||
|
||||
data += thislen;
|
||||
len -= thislen;
|
||||
}
|
||||
}
|
||||
|
||||
static void net_http_send_str(int fd, bool *error, const char *text)
|
||||
{
|
||||
#if 0
|
||||
printf("%s",text);
|
||||
#endif
|
||||
net_http_send(fd, error, text, strlen(text));
|
||||
if (!*error)
|
||||
{
|
||||
if (!socket_send_all_blocking(fd, text, strlen(text), true))
|
||||
*error = true;
|
||||
}
|
||||
}
|
||||
|
||||
static ssize_t net_http_recv(int fd, bool *error,
|
||||
@ -298,7 +278,7 @@ struct http_t *net_http_new(struct http_connection_t *conn)
|
||||
if (fd == -1)
|
||||
goto error;
|
||||
|
||||
error=false;
|
||||
error = false;
|
||||
|
||||
/* This is a bit lazy, but it works. */
|
||||
net_http_send_str(fd, &error, "GET /");
|
||||
|
@ -138,15 +138,22 @@ int socket_select(int nfds, fd_set *readfs, fd_set *writefds,
|
||||
#endif
|
||||
}
|
||||
|
||||
int socket_send_all_blocking(int fd, const void *data_, size_t size)
|
||||
int socket_send_all_blocking(int fd, const void *data_, size_t size,
|
||||
bool no_signal)
|
||||
{
|
||||
const uint8_t *data = (const uint8_t*)data_;
|
||||
|
||||
while (size)
|
||||
{
|
||||
ssize_t ret = send(fd, (const char*)data, size, 0);
|
||||
ssize_t ret = send(fd, (const char*)data, size,
|
||||
no_signal ? MSG_NOSIGNAL : 0);
|
||||
if (ret <= 0)
|
||||
{
|
||||
if (!isagain(ret))
|
||||
continue;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
data += ret;
|
||||
size -= ret;
|
||||
|
@ -200,13 +200,13 @@ static bool get_self_input_state(netplay_t *netplay)
|
||||
static bool netplay_cmd_ack(netplay_t *netplay)
|
||||
{
|
||||
uint32_t cmd = htonl(NETPLAY_CMD_ACK);
|
||||
return socket_send_all_blocking(netplay->fd, &cmd, sizeof(cmd));
|
||||
return socket_send_all_blocking(netplay->fd, &cmd, sizeof(cmd), false);
|
||||
}
|
||||
|
||||
static bool netplay_cmd_nak(netplay_t *netplay)
|
||||
{
|
||||
uint32_t cmd = htonl(NETPLAY_CMD_NAK);
|
||||
return socket_send_all_blocking(netplay->fd, &cmd, sizeof(cmd));
|
||||
return socket_send_all_blocking(netplay->fd, &cmd, sizeof(cmd), false);
|
||||
}
|
||||
|
||||
static bool netplay_get_response(netplay_t *netplay)
|
||||
@ -866,10 +866,10 @@ static bool netplay_send_raw_cmd(netplay_t *netplay, uint32_t cmd,
|
||||
cmd = (cmd << 16) | (size & 0xffff);
|
||||
cmd = htonl(cmd);
|
||||
|
||||
if (!socket_send_all_blocking(netplay->fd, &cmd, sizeof(cmd)))
|
||||
if (!socket_send_all_blocking(netplay->fd, &cmd, sizeof(cmd), false))
|
||||
return false;
|
||||
|
||||
if (!socket_send_all_blocking(netplay->fd, data, size))
|
||||
if (!socket_send_all_blocking(netplay->fd, data, size, false))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
@ -106,7 +106,7 @@ static void netplay_spectate_pre_frame(netplay_t *netplay)
|
||||
setsockopt(new_fd, SOL_SOCKET, SO_SNDBUF, (const char*)&bufsize,
|
||||
sizeof(int));
|
||||
|
||||
if (!socket_send_all_blocking(new_fd, header, header_size))
|
||||
if (!socket_send_all_blocking(new_fd, header, header_size, false))
|
||||
{
|
||||
RARCH_ERR("Failed to send header to client.\n");
|
||||
socket_close(new_fd);
|
||||
@ -145,7 +145,8 @@ static void netplay_spectate_post_frame(netplay_t *netplay)
|
||||
|
||||
if (socket_send_all_blocking(netplay->spectate.fds[i],
|
||||
netplay->spectate.input,
|
||||
netplay->spectate.input_ptr * sizeof(int16_t)))
|
||||
netplay->spectate.input_ptr * sizeof(int16_t),
|
||||
false))
|
||||
continue;
|
||||
|
||||
RARCH_LOG("Client (#%u) disconnected ...\n", i);
|
||||
|
Loading…
x
Reference in New Issue
Block a user