Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9221a9f0 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add read/write timeout to the audio sockets" into nyc-dev

parents 8b16db6f 783f2663
Loading
Loading
Loading
Loading
+14 −15
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@
#include <pthread.h>
#include <stdint.h>
#include <sys/errno.h>
#include <sys/poll.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
@@ -56,6 +55,7 @@

#define CTRL_CHAN_RETRY_COUNT 3
#define USEC_PER_SEC 1000000L
#define SOCK_SEND_RECV_TIMEOUT_MS 2000  /* Timeout for sending/receiving */

#define CASE_RETURN_STR(const) case const: return #const;

@@ -220,14 +220,23 @@ static int skt_connect(char *path, size_t buffer_sz)

    len = buffer_sz;
    ret = setsockopt(skt_fd, SOL_SOCKET, SO_SNDBUF, (char*)&len, (int)sizeof(len));

    /* only issue warning if failed */
    if (ret < 0)
        ERROR("setsockopt failed (%s)", strerror(errno));

    ret = setsockopt(skt_fd, SOL_SOCKET, SO_RCVBUF, (char*)&len, (int)sizeof(len));
    if (ret < 0)
        ERROR("setsockopt failed (%s)", strerror(errno));

    /* Socket send/receive timeout value */
    struct timeval tv;
    tv.tv_sec = SOCK_SEND_RECV_TIMEOUT_MS / 1000;
    tv.tv_usec = (SOCK_SEND_RECV_TIMEOUT_MS % 1000) * 1000;

    ret = setsockopt(skt_fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
    if (ret < 0)
        ERROR("setsockopt failed (%s)", strerror(errno));

    /* only issue warning if failed */
    ret = setsockopt(skt_fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
    if (ret < 0)
        ERROR("setsockopt failed (%s)", strerror(errno));

@@ -246,7 +255,7 @@ static int skt_read(int fd, void *p, size_t len)

    if ((read = recv(fd, p, len, MSG_NOSIGNAL)) == -1)
    {
        ERROR("write failed with errno=%d\n", errno);
        ERROR("read failed with errno=%d\n", errno);
        return -1;
    }

@@ -256,19 +265,9 @@ static int skt_read(int fd, void *p, size_t len)
static int skt_write(int fd, const void *p, size_t len)
{
    int sent;
    struct pollfd pfd;

    FNLOG();

    pfd.fd = fd;
    pfd.events = POLLOUT;

    /* poll for 500 ms */

    /* send time out */
    if (poll(&pfd, 1, 500) == 0)
        return 0;

    ts_log("skt_write", len, NULL);

    if ((sent = send(fd, p, len, MSG_NOSIGNAL)) == -1)