annotate tcp.c @ 506:74ad3aa6749c libavformat

2000/00/00 to 2001/03/01 QT fileformat documentation patch by (Sebastien Bechet <s.bechet at av7 dot net>)
author michael
date Wed, 28 Jul 2004 10:04:14 +0000
parents 0fdc96c2f2fe
children 056991ab9f10
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 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
18 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
19 #include "avformat.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20 #include <unistd.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21 #include <sys/types.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
22 #include <sys/socket.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
23 #include <netinet/in.h>
182
82fea3fec65b OSX and BeOS networking fix (socklen_t)
mmu_man
parents: 180
diff changeset
24 #if defined(__APPLE__) || defined(__BEOS__)
82fea3fec65b OSX and BeOS networking fix (socklen_t)
mmu_man
parents: 180
diff changeset
25 typedef int socklen_t;
82fea3fec65b OSX and BeOS networking fix (socklen_t)
mmu_man
parents: 180
diff changeset
26 #endif
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
27 #ifndef __BEOS__
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 # include <arpa/inet.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30 # include "barpainet.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
31 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
32 #include <netdb.h>
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
33 #include <sys/time.h>
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
34 #include <fcntl.h>
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
35
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
36 typedef struct TCPContext {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
37 int fd;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
38 } TCPContext;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
39
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40 /* resolve host with also IP address parsing */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41 int resolve_host(struct in_addr *sin_addr, const char *hostname)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43 struct hostent *hp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45 if ((inet_aton(hostname, sin_addr)) == 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46 hp = gethostbyname(hostname);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47 if (!hp)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49 memcpy (sin_addr, hp->h_addr, sizeof(struct in_addr));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
53
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54 /* return non zero if error */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55 static int tcp_open(URLContext *h, const char *uri, int flags)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
56 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57 struct sockaddr_in dest_addr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 char hostname[1024], *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59 int port, fd = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60 TCPContext *s;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61 const char *p;
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
62 fd_set wfds;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
63 int fd_max, ret;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
64 struct timeval tv;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
65 socklen_t optlen;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
66
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67 s = av_malloc(sizeof(TCPContext));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68 if (!s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69 return -ENOMEM;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70 h->priv_data = s;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
71 p = uri;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72 if (!strstart(p, "tcp://", &p))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
73 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74 q = hostname;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
75 while (*p != ':' && *p != '/' && *p != '\0') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
76 if ((q - hostname) < sizeof(hostname) - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
77 *q++ = *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
78 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 if (*p != ':')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 port = strtoul(p, (char **)&p, 10);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85 if (port <= 0 || port >= 65536)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88 dest_addr.sin_family = AF_INET;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89 dest_addr.sin_port = htons(port);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90 if (resolve_host(&dest_addr.sin_addr, hostname) < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
91 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
93 fd = socket(PF_INET, SOCK_STREAM, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
94 if (fd < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
95 goto fail;
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
96 fcntl(fd, F_SETFL, O_NONBLOCK);
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
97
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
98 redo:
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
99 ret = connect(fd, (struct sockaddr *)&dest_addr,
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
100 sizeof(dest_addr));
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
101 if (ret < 0) {
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
102 if (errno == EINTR)
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
103 goto redo;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
104 if (errno != EINPROGRESS)
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
105 goto fail;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
107 /* wait until we are connected or until abort */
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
108 for(;;) {
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
109 if (url_interrupt_cb()) {
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
110 ret = -EINTR;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
111 goto fail1;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
112 }
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
113 fd_max = fd;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
114 FD_ZERO(&wfds);
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
115 FD_SET(fd, &wfds);
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
116 tv.tv_sec = 0;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
117 tv.tv_usec = 100 * 1000;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
118 ret = select(fd_max + 1, NULL, &wfds, NULL, &tv);
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
119 if (ret > 0 && FD_ISSET(fd, &wfds))
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
120 break;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
121 }
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
122
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
123 /* test error */
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
124 optlen = sizeof(ret);
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
125 getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen);
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
126 if (ret != 0)
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
127 goto fail;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
128 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
129 s->fd = fd;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
130 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
131
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
132 fail:
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 388
diff changeset
133 ret = AVERROR_IO;
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
134 fail1:
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
135 if (fd >= 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
136 close(fd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
137 av_free(s);
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
138 return ret;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
139 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
140
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
141 static int tcp_read(URLContext *h, uint8_t *buf, int size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
142 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
143 TCPContext *s = h->priv_data;
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
144 int len, fd_max, ret;
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
145 fd_set rfds;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
146 struct timeval tv;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
147
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
148 for (;;) {
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
149 if (url_interrupt_cb())
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
150 return -EINTR;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
151 fd_max = s->fd;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
152 FD_ZERO(&rfds);
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
153 FD_SET(s->fd, &rfds);
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
154 tv.tv_sec = 0;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
155 tv.tv_usec = 100 * 1000;
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
156 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
157 if (ret > 0 && FD_ISSET(s->fd, &rfds)) {
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
158 #ifdef __BEOS__
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
159 len = recv(s->fd, buf, size, 0);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
160 #else
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
161 len = read(s->fd, buf, size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
162 #endif
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
163 if (len < 0) {
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
164 if (errno != EINTR && errno != EAGAIN)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
165 #ifdef __BEOS__
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
166 return errno;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
167 #else
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
168 return -errno;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
169 #endif
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
170 } else return len;
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
171 } else if (ret < 0) {
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
172 return -1;
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
173 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
174 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
175 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
176
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
177 static int tcp_write(URLContext *h, uint8_t *buf, int size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
178 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
179 TCPContext *s = h->priv_data;
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
180 int ret, size1, fd_max, len;
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
181 fd_set wfds;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
182 struct timeval tv;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
183
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
184 size1 = size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
185 while (size > 0) {
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
186 if (url_interrupt_cb())
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
187 return -EINTR;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
188 fd_max = s->fd;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
189 FD_ZERO(&wfds);
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
190 FD_SET(s->fd, &wfds);
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
191 tv.tv_sec = 0;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
192 tv.tv_usec = 100 * 1000;
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
193 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
194 if (ret > 0 && FD_ISSET(s->fd, &wfds)) {
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
195 #ifdef __BEOS__
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
196 len = send(s->fd, buf, size, 0);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
197 #else
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
198 len = write(s->fd, buf, size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
199 #endif
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
200 if (len < 0) {
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
201 if (errno != EINTR && errno != EAGAIN) {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
202 #ifdef __BEOS__
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
203 return errno;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
204 #else
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
205 return -errno;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
206 #endif
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
207 }
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
208 continue;
261
5f27f90ed496 Fix a very nasty problem with extra bytes appearing in TCP data streams.
philipjsg
parents: 229
diff changeset
209 }
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
210 size -= len;
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
211 buf += len;
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
212 } else if (ret < 0) {
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
213 return -1;
261
5f27f90ed496 Fix a very nasty problem with extra bytes appearing in TCP data streams.
philipjsg
parents: 229
diff changeset
214 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
215 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
216 return size1 - size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
217 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
218
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
219 static int tcp_close(URLContext *h)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
220 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
221 TCPContext *s = h->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
222 #ifdef CONFIG_BEOS_NETSERVER
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
223 closesocket(s->fd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
224 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
225 close(s->fd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
226 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
227 av_free(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
228 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
229 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
230
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
231 URLProtocol tcp_protocol = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
232 "tcp",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
233 tcp_open,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
234 tcp_read,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
235 tcp_write,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
236 NULL, /* seek */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
237 tcp_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
238 };