~ubuntu-branches/ubuntu/karmic/gnash/karmic

« back to all changes in this revision

Viewing changes to libnet/network.h

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack
  • Date: 2008-10-13 14:29:49 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20081013142949-f6qdvnu4mn05ltdc
Tags: 0.8.4~~bzr9980-0ubuntu1
* new upstream release 0.8.4 (LP: #240325)
* ship new lib usr/lib/gnash/libmozsdk.so.* in mozilla-plugin-gnash
  - update debian/mozilla-plugin-gnash.install
* ship new lib usr/lib/gnash/libgnashnet.so.* in gnash-common
  - update debian/gnash-common.install
* add basic debian/build_head script to build latest CVS head packages.
  - add debian/build_head
* new sound architecture requires build depend on libsdl1.2-dev
  - update debian/control
* head build script now has been completely migrated to bzr (upstream +
  ubuntu)
  - update debian/build_head
* disable kde gui until klash/qt4 has been fixed; keep kde packages as empty
  packages for now.
  - update debian/rules
  - debian/klash.install
  - debian/klash.links
  - debian/klash.manpages
  - debian/konqueror-plugin-gnash.install
* drop libkonq5-dev build dependency accordingly
  - update debian/control
* don't install headers manually anymore. gnash doesnt provide a -dev
  package after all
  - update debian/rules
* update libs installed in gnash-common; libgnashserver-*.so is not available
  anymore (removed); in turn we add the new libgnashcore-*.so
  - update debian/gnash-common.install
* use -Os for optimization and properly pass CXXFLAGS=$(CFLAGS) to configure
  - update debian/rules
* touch firefox .autoreg in postinst of mozilla plugin
  - update debian/mozilla-plugin-gnash.postinst
* link gnash in ubufox plugins directory for the plugin alternative switcher
  - add debian/mozilla-plugin-gnash.links
* suggest ubufox accordingly
  - update debian/control
* add new required build-depends on libgif-dev
  - update debian/control
* add Xb-Npp-Description and Xb-Npp-File as new plugin database meta data
  - update debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
//   Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
3
// 
 
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.
 
8
// 
 
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.
 
13
// 
 
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
 
17
 
 
18
#ifndef __NETWORK_H__
 
19
#define __NETWORK_H__
 
20
 
 
21
#ifdef HAVE_CONFIG_H
 
22
#include "gnashconfig.h"
 
23
#endif
 
24
 
 
25
#if !defined(HAVE_WINSOCK_H) || defined(__OS2__)
 
26
# include <sys/types.h>
 
27
# include <netinet/in.h>
 
28
# include <arpa/inet.h>
 
29
#else
 
30
# include <winsock2.h>
 
31
# include <windows.h>
 
32
# include <fcntl.h>
 
33
# include <sys/stat.h>
 
34
# include <io.h>
 
35
#endif
 
36
 
 
37
#include "dsodefs.h" //For DSOEXPORT.
 
38
#include <boost/cstdint.hpp>
 
39
#include <cassert>
 
40
#include <string>
 
41
 
 
42
namespace amf {
 
43
class Buffer;
 
44
}
 
45
 
 
46
namespace gnash {
 
47
 
 
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;
 
55
 
 
56
#ifdef __OS2__
 
57
 typedef int    socklen_t;
 
58
 #define SHUT_RDWR 0x2
 
59
#endif
 
60
 
 
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;
 
65
#endif
 
66
 
 
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
 
70
 
 
71
class DSOEXPORT Network {
 
72
public:
 
73
    typedef boost::uint8_t byte_t;
 
74
 
 
75
    Network();
 
76
    ~Network();
 
77
    
 
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);
 
82
    
 
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);
 
88
 
 
89
    // Connect to a named pipe
 
90
    bool connectSocket(const std::string &sock);
 
91
 
 
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);
 
97
 
 
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);
 
106
    
 
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);
 
114
    
 
115
    // Close the connection
 
116
    bool closeNet();
 
117
    bool closeNet(int fd);
 
118
    bool closeConnection();
 
119
    bool closeConnection(int fd);
 
120
 
 
121
    // Change the debug flag
 
122
    void toggleDebug(bool val);
 
123
    bool netDebug() { return _debug; };
 
124
    
 
125
    bool send(const char *str);
 
126
 
 
127
    // Accessors for testing
 
128
    bool connected()           
 
129
    {
 
130
        assert ( ( _connected && _sockfd > 0 ) || ( ! _connected && _sockfd <= 0 ) );
 
131
        return _connected;
 
132
    };
 
133
 
 
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; }
 
146
 
 
147
    // Network is not copiable !
 
148
    //Network &operator = (Network &net) {}
 
149
 
 
150
 protected:
 
151
    in_addr_t   _ipaddr;
 
152
    int         _sockfd;        // the file descriptor used for reading and writing
 
153
    int         _listenfd;      // the file descriptor used to listen for new connections
 
154
    short       _port;
 
155
    std::string _portstr;
 
156
    std::string _url;
 
157
    std::string _protocol;
 
158
    std::string _host;
 
159
    std::string _path;
 
160
    bool        _connected;
 
161
    bool        _debug;
 
162
    int         _timeout;
 
163
};
 
164
 
 
165
} // end of gnash namespace
 
166
 
 
167
// __NETWORK_H__
 
168
#endif
 
169
 
 
170
// Local Variables:
 
171
// mode: C++
 
172
// indent-tabs-mode: t
 
173
// End: