Ticket #1811: tcp.patch

File tcp.patch, 3.1 KB (added by steep8@…, 16 years ago)

patch to set send/recv tcp timeouts with command options.

  • stream/tcp.c

     
    5353
    5454/* IPv6 options */
    5555int   network_prefer_ipv4 = 0;
     56int recv_timeout = -1;
     57int send_timeout = -1;
    5658
     59void
     60setSockTimeout(int socket_server_fd, int timeout, int send_recv_option) {
     61#if HAVE_WINSOCK2_H
     62        int to;
     63#else
     64        struct timeval to;
     65#endif
     66
     67        int cur_timeout = 10;
     68        if(timeout > 0)
     69                cur_timeout = timeout;
     70
     71#if HAVE_WINSOCK2_H
     72        /* timeout in milliseconds */
     73        to = cur_timeout * 1000;
     74
     75#else
     76        to.tv_sec = cur_timeout;
     77        to.tv_usec = 0;
     78#endif
     79        setsockopt(socket_server_fd, SOL_SOCKET, send_recv_option, &to, sizeof(to));
     80}
     81
    5782// Converts an address family constant to a string
    5883
    5984static const char *af2String(int af) {
     
    94119
    95120#if HAVE_WINSOCK2_H
    96121        unsigned long val;
    97         int to;
    98 #else
    99         struct timeval to;
    100122#endif
    101123
    102124#if HAVE_WINSOCK2_H && defined(HAVE_AF_INET6)
     
    116138        }
    117139
    118140#if defined(SO_RCVTIMEO) && defined(SO_SNDTIMEO)
    119 #if HAVE_WINSOCK2_H
    120         /* timeout in milliseconds */
    121         to = 10 * 1000;
    122 #else
    123         to.tv_sec = 10;
    124         to.tv_usec = 0;
     141        if(send_timeout != 0)
     142                setSockTimeout(socket_server_fd, send_timeout, SO_RCVTIMEO);
     143
     144        if(recv_timeout != 0)
     145                setSockTimeout(socket_server_fd, recv_timeout, SO_RCVTIMEO);
    125146#endif
    126         setsockopt(socket_server_fd, SOL_SOCKET, SO_RCVTIMEO, &to, sizeof(to));
    127         setsockopt(socket_server_fd, SOL_SOCKET, SO_SNDTIMEO, &to, sizeof(to));
    128 #endif
    129147
    130148        switch (af) {
    131149                case AF_INET:  our_s_addr = (void *) &server_address.four.sin_addr; break;
  • stream/tcp.h

     
    2626#define MPLAYER_TCP_H
    2727
    2828extern int network_prefer_ipv4;
     29extern int send_timeout;
     30extern int recv_timeout;
    2931
    3032/* Connect to a server using a TCP connection */
    3133int connect2Server (char *host, int port, int verb);
  • DOCS/man/en/mplayer.1

     
    12241224.B \-udp\-slave
    12251225Listen on \-udp\-port and match the master's position.
    12261226.
     1227.TP
     1228.B \-send\-timeout <sec>
     1229Sets send timeout on tcp socket (default: 10).
     1230No timeout is set if sec = 0.
    12271231.
     1232.TP
     1233.B \-recv\-timeout <sec>
     1234Sets recv timeout on tcp socket (default: 10).
     1235No timeout is set if sec = 0.
     1236.
     1237.
    12281238.SH "DEMUXER/STREAM OPTIONS"
    12291239.
    12301240.TP
  • cfg-mplayer.h

     
    277277    {"udp-ip", &udp_ip, CONF_TYPE_STRING, 0, 0, 1, NULL},
    278278    {"udp-port", &udp_port, CONF_TYPE_INT, 0, 1, 65535, NULL},
    279279    {"udp-seek-threshold", &udp_seek_threshold, CONF_TYPE_FLOAT, CONF_RANGE, 0.1, 100, NULL},
     280    {"send-timeout", &send_timeout, CONF_TYPE_INT, CONF_RANGE, 0, 10000, NULL},
     281    {"recv-timeout", &recv_timeout, CONF_TYPE_INT, CONF_RANGE, 0, 10000, NULL},
    280282#endif /* CONFIG_NETWORKING */
    281283
    282284    // dump some stream out instead of playing the file