2
// Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
4
// This program is free software; you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation; either version 3 of the License, or
7
// (at your option) any later version.
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public License
15
// along with this program; if not, write to the Free Software
16
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
#include "gnashconfig.h"
25
#if !defined(HAVE_WINSOCK_H) || defined(__OS2__)
26
# include <sys/types.h>
27
# include <netinet/in.h>
28
# include <arpa/inet.h>
30
# include <winsock2.h>
33
# include <sys/stat.h>
37
#include "dsodefs.h" //For DSOEXPORT.
38
#include <boost/cstdint.hpp>
48
// Define the ports for the RTMP protocols
49
const short ADMIN_PORT = 1111;
50
const short RTMP_PORT = 1935;
51
const short RTMPE_PORT = 1935;
52
const short RTMPT_PORT = 80;
53
const short RTMPTE_PORT = 80;
54
const short RTMPTS_PORT = 443;
57
typedef int socklen_t;
61
#if defined(HAVE_WINSOCK_H) && !defined(__OS2__)
62
typedef long in_addr_t;
63
# define inet_lnaof(x) inet_addr(inet_ntoa(x))
64
typedef int socklen_t;
67
// Adjust for the constant size
68
const size_t NETBUFSIZE = 1448; // 1500 appears to be the default size as used by FMS
69
//const size_t NETBUFSIZE = 1357*2; // 1500 appears to be the default size as used by FMS
71
class DSOEXPORT Network {
73
typedef boost::uint8_t byte_t;
78
// Create a new server. After creating it, then you have to wait
79
// for an incoming connection.
80
int createServer(void);
81
int createServer(short port);
83
// Accept a client connection for the current server.
84
int newConnection(void);
85
int newConnection(int fd);
86
int newConnection(bool block, int fd);
87
int newConnection(bool block);
89
// Connect to a named pipe
90
bool connectSocket(const std::string &sock);
92
// Create a client connection to a tcp/ip server
93
bool createClient(void);
94
bool createClient(short port);
95
bool createClient(const std::string &hostname);
96
bool createClient(const std::string &hostname, short port);
98
// Read from the connection
99
amf::Buffer *readNet();
100
int readNet(amf::Buffer *buffer);
101
int readNet(amf::Buffer *buffer, int timeout);
102
int readNet(byte_t *buffer, int nbytes);
103
int readNet(byte_t *buffer, int nbytes, int timeout);
104
int readNet(int fd, byte_t *buffer, int nbytes);
105
int readNet(int fd, byte_t *buffer, int nbytes, int timeout);
107
// Write to the connection
108
int writeNet(amf::Buffer *buffer);
109
int writeNet(const std::string &buffer);
110
int writeNet(const byte_t *buffer, int nbytes);
111
// int writeNet(int fd, const byte_t *buffer);
112
int writeNet(int fd, const byte_t *buffer, int nbytes);
113
int writeNet(int fd, const byte_t *buffer, int nbytes, int timeout);
115
// Close the connection
117
bool closeNet(int fd);
118
bool closeConnection();
119
bool closeConnection(int fd);
121
// Change the debug flag
122
void toggleDebug(bool val);
123
bool netDebug() { return _debug; };
125
bool send(const char *str);
127
// Accessors for testing
130
assert ( ( _connected && _sockfd > 0 ) || ( ! _connected && _sockfd <= 0 ) );
134
void setPort(short x) { _port = x; };
135
short getPort() const { return _port; };
136
void setFileFd(int x) { _sockfd = x; };
137
int getFileFd() const { return _sockfd; };
138
int getListenFd() const { return _listenfd; };
139
void setListenFd(int x) { _listenfd = x; };
140
const std::string& getURL() const { return _url; }
141
const std::string& getProtocol() const { return _protocol; }
142
const std::string& getHost() const { return _host; }
143
const std::string& getPortStr() const { return _portstr; }
144
const std::string& getPath() const { return _path; }
145
int getTimeout() const { return _timeout; }
147
// Network is not copiable !
148
//Network &operator = (Network &net) {}
152
int _sockfd; // the file descriptor used for reading and writing
153
int _listenfd; // the file descriptor used to listen for new connections
155
std::string _portstr;
157
std::string _protocol;
165
} // end of gnash namespace
172
// indent-tabs-mode: t