From: <mr...@mr...> - 2004-08-10 00:48:01
|
# This is a BitKeeper generated diff -Nru style patch. # # ChangeSet # 2004/08/10 02:47:38+02:00 mr...@fo... = # simplify udp reading # users must now read entire udp packets # = # src/multicast/mc.c # 2004/08/10 02:47:37+02:00 mr...@fo... +32 -63 # remove buffering # = # src/multicast/TC2Module # 2004/08/10 02:47:36+02:00 mr...@fo... +0 -1 # remove option buffer_size # = diff -Nru a/src/multicast/TC2Module b/src/multicast/TC2Module --- a/src/multicast/TC2Module 2004-08-10 02:47:51 +02:00 +++ b/src/multicast/TC2Module 2004-08-10 02:47:51 +02:00 @@ -9,4 +9,3 @@ implement "URL/multicast" "close" mc_close implement "URL/udp" "open" mc_open sources mc.c -option buffer_size%i=3D65536 diff -Nru a/src/multicast/mc.c b/src/multicast/mc.c --- a/src/multicast/mc.c 2004-08-10 02:47:51 +02:00 +++ b/src/multicast/mc.c 2004-08-10 02:47:51 +02:00 @@ -1,3 +1,27 @@ +/** + Copyright (C) 2003-2004 Michael Ahlberg, M=C3=A5ns Rullg=C3=A5rd + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the "Software"), to deal in the Software without + restriction, including without limitation the rights to use, copy, + modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +**/ + #include <stdlib.h> #include <stdio.h> #include <unistd.h> @@ -9,53 +33,26 @@ #include <tcalloc.h> #include <udp_tc2.h> = -#define min(a,b) ((a)<(b)?(a):(b)) -#define max(a,b) ((a)>(b)?(a):(b)) - -#define buffer_size tc2_url_udp_conf_buffer_size - typedef struct mc_stream { int socket; struct sockaddr_in addr; uint64_t pos; - char *buf; - int bpos, bsize; } mc_stream_t; = extern int mc_read(void *buf, size_t size, size_t count, url_t *u) { mc_stream_t *mcs =3D u->private; - int s =3D size * count; + size_t s =3D size * count; + ssize_t r; = - while(s){ - int ss; + r =3D read(mcs->socket, buf, s); + if(r < 0) + return -1; = - if(mcs->bsize =3D=3D 0){ - struct sockaddr a; - int r, l =3D sizeof(a); - mcs->bpos =3D 0; - r =3D recvfrom(mcs->socket, mcs->buf, 65536, 0, &a, &l); - if(r < 0) - break; - mcs->bsize +=3D r; - } - - ss =3D min(s, mcs->bsize); - ss =3D min(ss, buffer_size - mcs->bpos); - memcpy(buf, mcs->buf + mcs->bpos, ss); - buf +=3D ss; - mcs->bpos +=3D ss; - mcs->bsize -=3D ss; - mcs->pos +=3D ss; - s -=3D ss; + mcs->pos +=3D r; = - if(mcs->bpos =3D=3D buffer_size) - mcs->bpos =3D 0; - } - - s =3D size * count - s; - return s / size; + return r / size; } = extern int @@ -77,32 +74,7 @@ extern int mc_seek(url_t *u, int64_t offset, int how) { - mc_stream_t *mcs =3D u->private; - uint64_t p, dp; - - switch(how){ - case SEEK_SET: - p =3D offset; - break; - case SEEK_CUR: - p =3D mcs->pos + offset; - break; - default: - return -1; - } - - dp =3D p - mcs->pos; - - if(dp > mcs->bsize) - return -1; - - if(dp < - mcs->bpos) - return -1; - - mcs->bpos +=3D dp; - mcs->bsize -=3D dp; - - return 0; + return -1; } = extern uint64_t @@ -118,7 +90,6 @@ mc_stream_t *mcs =3D u->private; = close(mcs->socket); - free(mcs->buf); tcfree(u); = return 0; @@ -190,8 +161,6 @@ mcs =3D calloc(1, sizeof(*mcs)); mcs->socket =3D sock; mcs->addr =3D sa; - - mcs->buf =3D malloc(max(buffer_size, 65536)); = u =3D tcallocz(sizeof(*u)); if(strchr(mode, 'r')) |