comparison tcp.c @ 388:9af30d452a0a libavformat

tcp select() check and enables pressing 'q' when reading/(writing) from tcp/http in ffmpeg.c patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
author michael
date Sun, 14 Mar 2004 19:40:43 +0000
parents 2f56d366a787
children 0fdc96c2f2fe
comparison
equal deleted inserted replaced
387:f2760852ed18 388:9af30d452a0a
139 } 139 }
140 140
141 static int tcp_read(URLContext *h, uint8_t *buf, int size) 141 static int tcp_read(URLContext *h, uint8_t *buf, int size)
142 { 142 {
143 TCPContext *s = h->priv_data; 143 TCPContext *s = h->priv_data;
144 int len, fd_max; 144 int len, fd_max, ret;
145 fd_set rfds; 145 fd_set rfds;
146 struct timeval tv; 146 struct timeval tv;
147 147
148 for (;;) { 148 for (;;) {
149 if (url_interrupt_cb()) 149 if (url_interrupt_cb())
151 fd_max = s->fd; 151 fd_max = s->fd;
152 FD_ZERO(&rfds); 152 FD_ZERO(&rfds);
153 FD_SET(s->fd, &rfds); 153 FD_SET(s->fd, &rfds);
154 tv.tv_sec = 0; 154 tv.tv_sec = 0;
155 tv.tv_usec = 100 * 1000; 155 tv.tv_usec = 100 * 1000;
156 select(fd_max + 1, &rfds, NULL, NULL, &tv); 156 ret = select(fd_max + 1, &rfds, NULL, NULL, &tv);
157 #ifdef __BEOS__ 157 if (ret > 0 && FD_ISSET(s->fd, &rfds)) {
158 len = recv(s->fd, buf, size, 0); 158 #ifdef __BEOS__
159 #else 159 len = recv(s->fd, buf, size, 0);
160 len = read(s->fd, buf, size); 160 #else
161 #endif 161 len = read(s->fd, buf, size);
162 if (len < 0) { 162 #endif
163 if (errno != EINTR && errno != EAGAIN) 163 if (len < 0) {
164 #ifdef __BEOS__ 164 if (errno != EINTR && errno != EAGAIN)
165 return errno; 165 #ifdef __BEOS__
166 #else 166 return errno;
167 return -errno; 167 #else
168 #endif 168 return -errno;
169 } else break; 169 #endif
170 } 170 } else return len;
171 return len; 171 } else if (ret < 0) {
172 return -1;
173 }
174 }
172 } 175 }
173 176
174 static int tcp_write(URLContext *h, uint8_t *buf, int size) 177 static int tcp_write(URLContext *h, uint8_t *buf, int size)
175 { 178 {
176 TCPContext *s = h->priv_data; 179 TCPContext *s = h->priv_data;
177 int ret, size1, fd_max; 180 int ret, size1, fd_max, len;
178 fd_set wfds; 181 fd_set wfds;
179 struct timeval tv; 182 struct timeval tv;
180 183
181 size1 = size; 184 size1 = size;
182 while (size > 0) { 185 while (size > 0) {
185 fd_max = s->fd; 188 fd_max = s->fd;
186 FD_ZERO(&wfds); 189 FD_ZERO(&wfds);
187 FD_SET(s->fd, &wfds); 190 FD_SET(s->fd, &wfds);
188 tv.tv_sec = 0; 191 tv.tv_sec = 0;
189 tv.tv_usec = 100 * 1000; 192 tv.tv_usec = 100 * 1000;
190 select(fd_max + 1, NULL, &wfds, NULL, &tv); 193 ret = select(fd_max + 1, NULL, &wfds, NULL, &tv);
191 #ifdef __BEOS__ 194 if (ret > 0 && FD_ISSET(s->fd, &wfds)) {
192 ret = send(s->fd, buf, size, 0); 195 #ifdef __BEOS__
193 #else 196 len = send(s->fd, buf, size, 0);
194 ret = write(s->fd, buf, size); 197 #else
195 #endif 198 len = write(s->fd, buf, size);
196 if (ret < 0) { 199 #endif
197 if (errno != EINTR && errno != EAGAIN) { 200 if (len < 0) {
198 #ifdef __BEOS__ 201 if (errno != EINTR && errno != EAGAIN) {
199 return errno; 202 #ifdef __BEOS__
200 #else 203 return errno;
201 return -errno; 204 #else
202 #endif 205 return -errno;
206 #endif
207 }
208 continue;
203 } 209 }
204 continue; 210 size -= len;
211 buf += len;
212 } else if (ret < 0) {
213 return -1;
205 } 214 }
206 size -= ret;
207 buf += ret;
208 } 215 }
209 return size1 - size; 216 return size1 - size;
210 } 217 }
211 218
212 static int tcp_close(URLContext *h) 219 static int tcp_close(URLContext *h)