comparison udp.c @ 1670:92afee454599 libavformat

The long awaited BeOS cleanup, phase 1
author mmu_man
date Thu, 18 Jan 2007 17:22:30 +0000
parents 7316227e64eb
children f695f8fc4a63
comparison
equal deleted inserted replaced
1669:30b51285b882 1670:92afee454599
21 #include "avformat.h" 21 #include "avformat.h"
22 #include <unistd.h> 22 #include <unistd.h>
23 #include <sys/types.h> 23 #include <sys/types.h>
24 #include <sys/socket.h> 24 #include <sys/socket.h>
25 #include <netinet/in.h> 25 #include <netinet/in.h>
26 #ifndef __BEOS__
27 # include <arpa/inet.h> 26 # include <arpa/inet.h>
28 #else
29 # include "barpainet.h"
30 #endif
31 #include <netdb.h> 27 #include <netdb.h>
32 28
33 #ifndef IPV6_ADD_MEMBERSHIP 29 #ifndef IPV6_ADD_MEMBERSHIP
34 #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP 30 #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
35 #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP 31 #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
212 208
213 return udp_fd; 209 return udp_fd;
214 210
215 fail: 211 fail:
216 if (udp_fd >= 0) 212 if (udp_fd >= 0)
217 #ifdef CONFIG_BEOS_NETSERVER
218 closesocket(udp_fd); 213 closesocket(udp_fd);
219 #else
220 close(udp_fd);
221 #endif
222 if(res0) 214 if(res0)
223 freeaddrinfo(res0); 215 freeaddrinfo(res0);
224 return -1; 216 return -1;
225 } 217 }
226 218
419 411
420 s->udp_fd = udp_fd; 412 s->udp_fd = udp_fd;
421 return 0; 413 return 0;
422 fail: 414 fail:
423 if (udp_fd >= 0) 415 if (udp_fd >= 0)
424 #ifdef CONFIG_BEOS_NETSERVER
425 closesocket(udp_fd); 416 closesocket(udp_fd);
426 #else
427 close(udp_fd);
428 #endif
429 av_free(s); 417 av_free(s);
430 return AVERROR_IO; 418 return AVERROR_IO;
431 } 419 }
432 420
433 static int udp_read(URLContext *h, uint8_t *buf, int size) 421 static int udp_read(URLContext *h, uint8_t *buf, int size)
480 468
481 static int udp_close(URLContext *h) 469 static int udp_close(URLContext *h)
482 { 470 {
483 UDPContext *s = h->priv_data; 471 UDPContext *s = h->priv_data;
484 472
485 #ifndef CONFIG_BEOS_NETSERVER 473 #ifndef CONFIG_IPV6
486 #ifndef CONFIG_IPV6 474 #ifdef IP_DROP_MEMBERSHIP
487 if (s->is_multicast && !(h->flags & URL_WRONLY)) { 475 if (s->is_multicast && !(h->flags & URL_WRONLY)) {
488 if (setsockopt(s->udp_fd, IPPROTO_IP, IP_DROP_MEMBERSHIP, 476 if (setsockopt(s->udp_fd, IPPROTO_IP, IP_DROP_MEMBERSHIP,
489 &s->mreq, sizeof(s->mreq)) < 0) { 477 &s->mreq, sizeof(s->mreq)) < 0) {
490 perror("IP_DROP_MEMBERSHIP"); 478 perror("IP_DROP_MEMBERSHIP");
491 } 479 }
492 } 480 }
481 #endif
493 #else 482 #else
494 if (s->is_multicast && !(h->flags & URL_WRONLY)) 483 if (s->is_multicast && !(h->flags & URL_WRONLY))
495 udp_ipv6_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr); 484 udp_ipv6_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr);
496 #endif 485 #endif
497 close(s->udp_fd);
498 #else
499 closesocket(s->udp_fd); 486 closesocket(s->udp_fd);
500 #endif
501 av_free(s); 487 av_free(s);
502 return 0; 488 return 0;
503 } 489 }
504 490
505 URLProtocol udp_protocol = { 491 URLProtocol udp_protocol = {