annotate tcp.c @ 622:d4f80b13d981 libavformat

10l (double free)
author michael
date Sun, 19 Dec 2004 20:25:55 +0000
parents 056991ab9f10
children 095009fc2f35
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;
511
056991ab9f10 HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents: 482
diff changeset
66 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
67
056991ab9f10 HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents: 482
diff changeset
68 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
69 &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
70 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
71 if ((q = strchr(hostname,'@'))) { strcpy(tmp,q+1); strcpy(hostname,tmp); } // PETR: take only the part after '@' for tcp protocol
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
72
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
73 s = av_malloc(sizeof(TCPContext));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74 if (!s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
75 return -ENOMEM;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
76 h->priv_data = s;
511
056991ab9f10 HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents: 482
diff changeset
77
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
78 if (port <= 0 || port >= 65536)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 dest_addr.sin_family = AF_INET;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82 dest_addr.sin_port = htons(port);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 if (resolve_host(&dest_addr.sin_addr, hostname) < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86 fd = socket(PF_INET, SOCK_STREAM, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87 if (fd < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88 goto fail;
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
89 fcntl(fd, F_SETFL, O_NONBLOCK);
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
90
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
91 redo:
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
92 ret = connect(fd, (struct sockaddr *)&dest_addr,
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
93 sizeof(dest_addr));
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
94 if (ret < 0) {
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
95 if (errno == EINTR)
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
96 goto redo;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
97 if (errno != EINPROGRESS)
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
98 goto fail;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
100 /* wait until we are connected or until abort */
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
101 for(;;) {
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
102 if (url_interrupt_cb()) {
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
103 ret = -EINTR;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
104 goto fail1;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
105 }
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
106 fd_max = fd;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
107 FD_ZERO(&wfds);
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
108 FD_SET(fd, &wfds);
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
109 tv.tv_sec = 0;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
110 tv.tv_usec = 100 * 1000;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
111 ret = select(fd_max + 1, NULL, &wfds, NULL, &tv);
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
112 if (ret > 0 && FD_ISSET(fd, &wfds))
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
113 break;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
114 }
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
115
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
116 /* test error */
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
117 optlen = sizeof(ret);
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
118 getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen);
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
119 if (ret != 0)
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
120 goto fail;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
121 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
122 s->fd = fd;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
123 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
124
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
125 fail:
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 388
diff changeset
126 ret = AVERROR_IO;
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
127 fail1:
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
128 if (fd >= 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
129 close(fd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
130 av_free(s);
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
131 return ret;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
132 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
133
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
134 static int tcp_read(URLContext *h, uint8_t *buf, int size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
135 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
136 TCPContext *s = h->priv_data;
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
137 int len, fd_max, ret;
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
138 fd_set rfds;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
139 struct timeval tv;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
140
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
141 for (;;) {
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
142 if (url_interrupt_cb())
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
143 return -EINTR;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
144 fd_max = s->fd;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
145 FD_ZERO(&rfds);
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
146 FD_SET(s->fd, &rfds);
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
147 tv.tv_sec = 0;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
148 tv.tv_usec = 100 * 1000;
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
149 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
150 if (ret > 0 && FD_ISSET(s->fd, &rfds)) {
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
151 #ifdef __BEOS__
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
152 len = recv(s->fd, buf, size, 0);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
153 #else
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
154 len = read(s->fd, buf, size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
155 #endif
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
156 if (len < 0) {
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
157 if (errno != EINTR && errno != EAGAIN)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
158 #ifdef __BEOS__
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
159 return errno;
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 return -errno;
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 } else return len;
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
164 } else if (ret < 0) {
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
165 return -1;
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
166 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
167 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
168 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
169
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
170 static int tcp_write(URLContext *h, uint8_t *buf, int size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
171 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
172 TCPContext *s = h->priv_data;
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
173 int ret, size1, fd_max, len;
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
174 fd_set wfds;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
175 struct timeval tv;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
176
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
177 size1 = size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
178 while (size > 0) {
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
179 if (url_interrupt_cb())
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
180 return -EINTR;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
181 fd_max = s->fd;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
182 FD_ZERO(&wfds);
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
183 FD_SET(s->fd, &wfds);
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
184 tv.tv_sec = 0;
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
185 tv.tv_usec = 100 * 1000;
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
186 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
187 if (ret > 0 && FD_ISSET(s->fd, &wfds)) {
180
9e673f620f4d support aborting in TCP
bellard
parents: 65
diff changeset
188 #ifdef __BEOS__
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
189 len = send(s->fd, buf, size, 0);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
190 #else
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
191 len = write(s->fd, buf, size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
192 #endif
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
193 if (len < 0) {
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
194 if (errno != EINTR && errno != EAGAIN) {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
195 #ifdef __BEOS__
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
196 return errno;
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 return -errno;
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 }
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
201 continue;
261
5f27f90ed496 Fix a very nasty problem with extra bytes appearing in TCP data streams.
philipjsg
parents: 229
diff changeset
202 }
388
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
203 size -= len;
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
204 buf += len;
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
205 } else if (ret < 0) {
9af30d452a0a tcp select() check and enables pressing 'q' when reading/(writing) from
michael
parents: 385
diff changeset
206 return -1;
261
5f27f90ed496 Fix a very nasty problem with extra bytes appearing in TCP data streams.
philipjsg
parents: 229
diff changeset
207 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
208 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
209 return size1 - size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
210 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
211
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
212 static int tcp_close(URLContext *h)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
213 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
214 TCPContext *s = h->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
215 #ifdef CONFIG_BEOS_NETSERVER
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
216 closesocket(s->fd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
217 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
218 close(s->fd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
219 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
220 av_free(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
221 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
222 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
223
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
224 URLProtocol tcp_protocol = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
225 "tcp",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
226 tcp_open,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
227 tcp_read,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
228 tcp_write,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
229 NULL, /* seek */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
230 tcp_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
231 };