annotate tcp.c @ 1504:03ff0a61a23c libavformat

add 422P@HL I-only universal label
author bcoudurier
date Tue, 14 Nov 2006 14:54:40 +0000
parents 0899bfe4105c
children 92afee454599
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
2 * TCP protocol
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
3 * Copyright (c) 2002 Fabrice Bellard.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
4 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 923
diff changeset
5 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 923
diff changeset
6 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 923
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 923
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 923
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 923
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 885
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21 #include "avformat.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
22 #include <unistd.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
23 #include <sys/types.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
24 #include <sys/socket.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
25 #include <netinet/in.h>
923
76c5dfe0b805 os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents: 896
diff changeset
26 #if defined(__BEOS__) || defined(__INNOTEK_LIBC__)
182
82fea3fec65b OSX and BeOS networking fix (socklen_t)
mmu_man
parents: 180
diff changeset
27 typedef int socklen_t;
82fea3fec65b OSX and BeOS networking fix (socklen_t)
mmu_man
parents: 180
diff changeset
28 #endif
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29 #ifndef __BEOS__
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30 # include <arpa/inet.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
31 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
32 # include "barpainet.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
33 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
34 #include <netdb.h>
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
35 #include <sys/time.h>
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
36 #include <fcntl.h>
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
37
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
38 typedef struct TCPContext {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
39 int fd;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40 } TCPContext;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42 /* resolve host with also IP address parsing */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43 int resolve_host(struct in_addr *sin_addr, const char *hostname)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45 struct hostent *hp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47 if ((inet_aton(hostname, sin_addr)) == 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48 hp = gethostbyname(hostname);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49 if (!hp)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51 memcpy (sin_addr, hp->h_addr, sizeof(struct in_addr));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
53 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
56 /* return non zero if error */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57 static int tcp_open(URLContext *h, const char *uri, int flags)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59 struct sockaddr_in dest_addr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60 char hostname[1024], *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61 int port, fd = -1;
683
095009fc2f35 kill warnings patch by (Mns Rullgrd <mru inprovide com>)
michael
parents: 511
diff changeset
62 TCPContext *s = NULL;
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
63 fd_set wfds;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
64 int fd_max, ret;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
65 struct timeval tv;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
66 socklen_t optlen;
511
056991ab9f10 HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents: 482
diff changeset
67 char proto[1024],path[1024],tmp[1024]; // PETR: protocol and path strings
056991ab9f10 HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents: 482
diff changeset
68
056991ab9f10 HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents: 482
diff changeset
69 url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname),
056991ab9f10 HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents: 482
diff changeset
70 &port, path, sizeof(path), uri); // PETR: use url_split
056991ab9f10 HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents: 482
diff changeset
71 if (strcmp(proto,"tcp")) goto fail; // PETR: check protocol
056991ab9f10 HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents: 482
diff changeset
72 if ((q = strchr(hostname,'@'))) { strcpy(tmp,q+1); strcpy(hostname,tmp); } // PETR: take only the part after '@' for tcp protocol
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 753
diff changeset
73
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74 s = av_malloc(sizeof(TCPContext));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
75 if (!s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
76 return -ENOMEM;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
77 h->priv_data = s;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 753
diff changeset
78
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 if (port <= 0 || port >= 65536)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80 goto fail;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 753
diff changeset
81
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82 dest_addr.sin_family = AF_INET;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 dest_addr.sin_port = htons(port);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 if (resolve_host(&dest_addr.sin_addr, hostname) < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87 fd = socket(PF_INET, SOCK_STREAM, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88 if (fd < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89 goto fail;
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
90 fcntl(fd, F_SETFL, O_NONBLOCK);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 753
diff changeset
91
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
92 redo:
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 753
diff changeset
93 ret = connect(fd, (struct sockaddr *)&dest_addr,
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
94 sizeof(dest_addr));
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
95 if (ret < 0) {
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
96 if (errno == EINTR)
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
97 goto redo;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
98 if (errno != EINPROGRESS)
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
99 goto fail;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
100
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
101 /* wait until we are connected or until abort */
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
102 for(;;) {
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
103 if (url_interrupt_cb()) {
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
104 ret = -EINTR;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
105 goto fail1;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
106 }
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
107 fd_max = fd;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
108 FD_ZERO(&wfds);
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
109 FD_SET(fd, &wfds);
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
110 tv.tv_sec = 0;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
111 tv.tv_usec = 100 * 1000;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
112 ret = select(fd_max + 1, NULL, &wfds, NULL, &tv);
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
113 if (ret > 0 && FD_ISSET(fd, &wfds))
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
114 break;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
115 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 753
diff changeset
116
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
117 /* test error */
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
118 optlen = sizeof(ret);
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
119 getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen);
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
120 if (ret != 0)
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
121 goto fail;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
122 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
123 s->fd = fd;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
124 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
125
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
126 fail:
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 388
diff changeset
127 ret = AVERROR_IO;
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
128 fail1:
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
129 if (fd >= 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
130 close(fd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
131 av_free(s);
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
132 return ret;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
133 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
134
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
135 static int tcp_read(URLContext *h, uint8_t *buf, int size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
136 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
137 TCPContext *s = h->priv_data;
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
138 int len, fd_max, ret;
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
139 fd_set rfds;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
140 struct timeval tv;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
141
385
2f56d366a787 no read loop tcp/http and http CRLF fix by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents: 261
diff changeset
142 for (;;) {
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
143 if (url_interrupt_cb())
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
144 return -EINTR;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
145 fd_max = s->fd;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
146 FD_ZERO(&rfds);
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
147 FD_SET(s->fd, &rfds);
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
148 tv.tv_sec = 0;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
149 tv.tv_usec = 100 * 1000;
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
150 ret = select(fd_max + 1, &rfds, NULL, NULL, &tv);
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
151 if (ret > 0 && FD_ISSET(s->fd, &rfds)) {
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
152 #ifdef __BEOS__
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
153 len = recv(s->fd, buf, size, 0);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
154 #else
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
155 len = read(s->fd, buf, size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
156 #endif
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
157 if (len < 0) {
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
158 if (errno != EINTR && errno != EAGAIN)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
159 #ifdef __BEOS__
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
160 return errno;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
161 #else
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
162 return -errno;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
163 #endif
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
164 } else return len;
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
165 } else if (ret < 0) {
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
166 return -1;
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
167 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
168 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
169 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
170
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
171 static int tcp_write(URLContext *h, uint8_t *buf, int size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
172 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
173 TCPContext *s = h->priv_data;
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
174 int ret, size1, fd_max, len;
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
175 fd_set wfds;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
176 struct timeval tv;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
177
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
178 size1 = size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
179 while (size > 0) {
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
180 if (url_interrupt_cb())
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
181 return -EINTR;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
182 fd_max = s->fd;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
183 FD_ZERO(&wfds);
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
184 FD_SET(s->fd, &wfds);
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
185 tv.tv_sec = 0;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
186 tv.tv_usec = 100 * 1000;
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
187 ret = select(fd_max + 1, NULL, &wfds, NULL, &tv);
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
188 if (ret > 0 && FD_ISSET(s->fd, &wfds)) {
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
189 #ifdef __BEOS__
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
190 len = send(s->fd, buf, size, 0);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
191 #else
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
192 len = write(s->fd, buf, size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
193 #endif
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
194 if (len < 0) {
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
195 if (errno != EINTR && errno != EAGAIN) {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
196 #ifdef __BEOS__
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
197 return errno;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
198 #else
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
199 return -errno;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
200 #endif
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
201 }
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
202 continue;
261
5f27f90ed496 Fix a very nasty problem with extra bytes appearing in TCP data streams.
philipjsg
parents: 229
diff changeset
203 }
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
204 size -= len;
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
205 buf += len;
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
206 } else if (ret < 0) {
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
207 return -1;
261
5f27f90ed496 Fix a very nasty problem with extra bytes appearing in TCP data streams.
philipjsg
parents: 229
diff changeset
208 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
209 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
210 return size1 - size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
211 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
212
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
213 static int tcp_close(URLContext *h)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
214 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
215 TCPContext *s = h->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
216 #ifdef CONFIG_BEOS_NETSERVER
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
217 closesocket(s->fd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
218 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
219 close(s->fd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
220 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
221 av_free(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
222 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
223 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
224
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
225 URLProtocol tcp_protocol = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
226 "tcp",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
227 tcp_open,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
228 tcp_read,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
229 tcp_write,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
230 NULL, /* seek */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
231 tcp_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
232 };