Commit 9ddd71fc authored by François Revol's avatar François Revol Committed by Michael Niedermayer

added BeOS net_server support (R5 network stack), basically the same

problems as with winsock (sockets != fd), and the broken select().
based on older patch by Andrew Bachmann.
patch by (François Revol <revol at free dot fr>)

Originally committed as revision 1144 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent bbd8335b
...@@ -27,10 +27,6 @@ ...@@ -27,10 +27,6 @@
#include <termios.h> #include <termios.h>
#include <sys/resource.h> #include <sys/resource.h>
#endif #endif
#ifdef __BEOS__
/* for snooze() */
#include <OS.h>
#endif
#include <time.h> #include <time.h>
#include <ctype.h> #include <ctype.h>
...@@ -227,14 +223,18 @@ static void term_init(void) ...@@ -227,14 +223,18 @@ static void term_init(void)
tcsetattr (0, TCSANOW, &tty); tcsetattr (0, TCSANOW, &tty);
atexit(term_exit); atexit(term_exit);
#ifdef CONFIG_BEOS_NETSERVER
fcntl(0, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK);
#endif
} }
/* read a key without blocking */ /* read a key without blocking */
static int read_key(void) static int read_key(void)
{ {
struct timeval tv; int n = 1;
int n;
unsigned char ch; unsigned char ch;
#ifndef CONFIG_BEOS_NETSERVER
struct timeval tv;
fd_set rfds; fd_set rfds;
FD_ZERO(&rfds); FD_ZERO(&rfds);
...@@ -242,6 +242,7 @@ static int read_key(void) ...@@ -242,6 +242,7 @@ static int read_key(void)
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = 0; tv.tv_usec = 0;
n = select(1, &rfds, NULL, NULL, &tv); n = select(1, &rfds, NULL, NULL, &tv);
#endif
if (n > 0) { if (n > 0) {
n = read(0, &ch, 1); n = read(0, &ch, 1);
if (n == 1) if (n == 1)
......
...@@ -31,6 +31,10 @@ endif ...@@ -31,6 +31,10 @@ endif
ifeq ($(CONFIG_NETWORK),yes) ifeq ($(CONFIG_NETWORK),yes)
OBJS+= udp.o tcp.o http.o rtsp.o rtp.o rtpproto.o OBJS+= udp.o tcp.o http.o rtsp.o rtp.o rtpproto.o
# BeOS network stuff
ifeq ($(CONFIG_BEOS_NETSERVER),yes)
OBJS+= barpainet.o
endif
endif endif
ifeq ($(CONFIG_VORBIS),yes) ifeq ($(CONFIG_VORBIS),yes)
......
#include <stdlib.h>
#include <strings.h>
#include "barpainet.h"
int inet_aton (const char * str, struct in_addr * add) {
const char * pch = str;
unsigned int add1 = 0, add2 = 0, add3 = 0, add4 = 0;
add1 = atoi(pch);
pch = strpbrk(pch,".");
if (pch == 0 || ++pch == 0) goto done;
add2 = atoi(pch);
pch = strpbrk(pch,".");
if (pch == 0 || ++pch == 0) goto done;
add3 = atoi(pch);
pch = strpbrk(pch,".");
if (pch == 0 || ++pch == 0) goto done;
add4 = atoi(pch);
done:
add->s_addr=(add4<<24)+(add3<<16)+(add2<<8)+add1;
return 1;
}
#ifndef BARPA_INET_H
#define BARPA_INET_H
#include "../config.h"
#ifdef CONFIG_BEOS_NETSERVER
# include <socket.h>
int inet_aton (const char * str, struct in_addr * add);
# define PF_INET AF_INET
# define SO_SNDBUF 0x40000001
/* fake */
struct ip_mreq {
struct in_addr imr_multiaddr; /* IP multicast address of group */
struct in_addr imr_interface; /* local IP address of interface */
};
#else
# include <arpa/inet.h>
#endif
#endif /* BARPA_INET_H */
...@@ -22,7 +22,11 @@ ...@@ -22,7 +22,11 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #ifndef __BEOS__
# include <arpa/inet.h>
#else
# include "barpainet.h"
#endif
#include <netdb.h> #include <netdb.h>
......
...@@ -22,7 +22,11 @@ ...@@ -22,7 +22,11 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #ifndef __BEOS__
# include <arpa/inet.h>
#else
# include "barpainet.h"
#endif
#include <netdb.h> #include <netdb.h>
//#define DEBUG //#define DEBUG
......
...@@ -23,7 +23,11 @@ ...@@ -23,7 +23,11 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #ifndef __BEOS__
# include <arpa/inet.h>
#else
# include "barpainet.h"
#endif
#include <netdb.h> #include <netdb.h>
#include <fcntl.h> #include <fcntl.h>
......
...@@ -21,7 +21,11 @@ ...@@ -21,7 +21,11 @@
#include <sys/time.h> #include <sys/time.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <arpa/inet.h> #ifndef __BEOS__
# include <arpa/inet.h>
#else
# include "barpainet.h"
#endif
//#define DEBUG //#define DEBUG
......
...@@ -22,7 +22,11 @@ ...@@ -22,7 +22,11 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #ifndef __BEOS__
# include <arpa/inet.h>
#else
# include "barpainet.h"
#endif
#include <netdb.h> #include <netdb.h>
typedef struct TCPContext { typedef struct TCPContext {
...@@ -103,10 +107,18 @@ static int tcp_read(URLContext *h, UINT8 *buf, int size) ...@@ -103,10 +107,18 @@ static int tcp_read(URLContext *h, UINT8 *buf, int size)
size1 = size; size1 = size;
while (size > 0) { while (size > 0) {
#ifdef CONFIG_BEOS_NETSERVER
len = recv (s->fd, buf, size, 0);
#else
len = read (s->fd, buf, size); len = read (s->fd, buf, size);
#endif
if (len < 0) { if (len < 0) {
if (errno != EINTR && errno != EAGAIN) if (errno != EINTR && errno != EAGAIN)
#ifdef __BEOS__
return errno;
#else
return -errno; return -errno;
#endif
else else
continue; continue;
} else if (len == 0) { } else if (len == 0) {
...@@ -125,9 +137,17 @@ static int tcp_write(URLContext *h, UINT8 *buf, int size) ...@@ -125,9 +137,17 @@ static int tcp_write(URLContext *h, UINT8 *buf, int size)
size1 = size; size1 = size;
while (size > 0) { while (size > 0) {
#ifdef CONFIG_BEOS_NETSERVER
ret = send (s->fd, buf, size, 0);
#else
ret = write (s->fd, buf, size); ret = write (s->fd, buf, size);
#endif
if (ret < 0 && errno != EINTR && errno != EAGAIN) if (ret < 0 && errno != EINTR && errno != EAGAIN)
#ifdef __BEOS__
return errno;
#else
return -errno; return -errno;
#endif
size -= ret; size -= ret;
buf += ret; buf += ret;
} }
...@@ -137,7 +157,11 @@ static int tcp_write(URLContext *h, UINT8 *buf, int size) ...@@ -137,7 +157,11 @@ static int tcp_write(URLContext *h, UINT8 *buf, int size)
static int tcp_close(URLContext *h) static int tcp_close(URLContext *h)
{ {
TCPContext *s = h->priv_data; TCPContext *s = h->priv_data;
#ifdef CONFIG_BEOS_NETSERVER
closesocket(s->fd);
#else
close(s->fd); close(s->fd);
#endif
av_free(s); av_free(s);
return 0; return 0;
} }
......
...@@ -21,7 +21,11 @@ ...@@ -21,7 +21,11 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #ifndef __BEOS__
# include <arpa/inet.h>
#else
# include "barpainet.h"
#endif
#include <netdb.h> #include <netdb.h>
typedef struct { typedef struct {
...@@ -154,6 +158,7 @@ static int udp_open(URLContext *h, const char *uri, int flags) ...@@ -154,6 +158,7 @@ static int udp_open(URLContext *h, const char *uri, int flags)
getsockname(udp_fd, (struct sockaddr *)&my_addr1, &len); getsockname(udp_fd, (struct sockaddr *)&my_addr1, &len);
s->local_port = ntohs(my_addr1.sin_port); s->local_port = ntohs(my_addr1.sin_port);
#ifndef CONFIG_BEOS_NETSERVER
if (s->is_multicast) { if (s->is_multicast) {
if (h->flags & URL_WRONLY) { if (h->flags & URL_WRONLY) {
/* output */ /* output */
...@@ -174,6 +179,7 @@ static int udp_open(URLContext *h, const char *uri, int flags) ...@@ -174,6 +179,7 @@ static int udp_open(URLContext *h, const char *uri, int flags)
} }
} }
} }
#endif
if (is_output) { if (is_output) {
/* limit the tx buf size to limit latency */ /* limit the tx buf size to limit latency */
...@@ -189,7 +195,11 @@ static int udp_open(URLContext *h, const char *uri, int flags) ...@@ -189,7 +195,11 @@ static int udp_open(URLContext *h, const char *uri, int flags)
return 0; return 0;
fail: fail:
if (udp_fd >= 0) if (udp_fd >= 0)
#ifdef CONFIG_BEOS_NETSERVER
closesocket(udp_fd);
#else
close(udp_fd); close(udp_fd);
#endif
av_free(s); av_free(s);
return -EIO; return -EIO;
} }
...@@ -237,6 +247,7 @@ static int udp_close(URLContext *h) ...@@ -237,6 +247,7 @@ static int udp_close(URLContext *h)
{ {
UDPContext *s = h->priv_data; UDPContext *s = h->priv_data;
#ifndef CONFIG_BEOS_NETSERVER
if (s->is_multicast && !(h->flags & URL_WRONLY)) { if (s->is_multicast && !(h->flags & URL_WRONLY)) {
if (setsockopt(s->udp_fd, IPPROTO_IP, IP_DROP_MEMBERSHIP, if (setsockopt(s->udp_fd, IPPROTO_IP, IP_DROP_MEMBERSHIP,
&s->mreq, sizeof(s->mreq)) < 0) { &s->mreq, sizeof(s->mreq)) < 0) {
...@@ -244,6 +255,9 @@ static int udp_close(URLContext *h) ...@@ -244,6 +255,9 @@ static int udp_close(URLContext *h)
} }
} }
close(s->udp_fd); close(s->udp_fd);
#else
closesocket(s->udp_fd);
#endif
av_free(s); av_free(s);
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment