annotate tcp.c @ 804:6a0cd265adbb libavformat

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