[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/rtmp r9708: get waitForNetData() working.
From: |
rob |
Subject: |
[Gnash-commit] /srv/bzr/gnash/rtmp r9708: get waitForNetData() working. |
Date: |
Thu, 06 Nov 2008 15:41:17 -0700 |
User-agent: |
Bazaar (1.5) |
------------------------------------------------------------
revno: 9708
committer: address@hidden
branch nick: rtmp
timestamp: Thu 2008-11-06 15:41:17 -0700
message:
get waitForNetData() working.
modified:
libnet/network.cpp
libnet/network.h
=== modified file 'libnet/network.cpp'
--- a/libnet/network.cpp 2008-11-01 15:00:27 +0000
+++ b/libnet/network.cpp 2008-11-06 22:41:17 +0000
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-//
+//xs
#ifdef HAVE_CONFIG_H
#include "gnashconfig.h"
@@ -60,6 +60,7 @@
#endif
#include "buffer.h"
+#include "GnashException.h"
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 256
@@ -67,6 +68,8 @@
using namespace std;
+/// \namespace gnash
+/// This is the main namespace for Gnash and it's libraries.
namespace gnash {
static const char *DEFAULTPROTO = "tcp";
@@ -602,7 +605,7 @@
bool
Network::closeNet()
{
- GNASH_REPORT_FUNCTION;
+// GNASH_REPORT_FUNCTION;
if ((_sockfd > 0) && (_connected)) {
closeNet(_sockfd);
@@ -616,7 +619,7 @@
bool
Network::closeNet(int sockfd)
{
- GNASH_REPORT_FUNCTION;
+// GNASH_REPORT_FUNCTION;
int retries = 0;
@@ -682,7 +685,7 @@
bool
Network::closeConnection(int fd)
{
- GNASH_REPORT_FUNCTION;
+// GNASH_REPORT_FUNCTION;
if (fd > 0) {
::close(fd);
@@ -947,34 +950,65 @@
return ret;
}
-//boost::shared_ptr<vector<int> >
-boost::shared_ptr<std::vector<int> >
+boost::shared_ptr<std::vector<struct pollfd> >
Network::waitForNetData(int limit, struct pollfd *fds)
{
-// GNASH_REPORT_FUNCTION;
+ GNASH_REPORT_FUNCTION;
- boost::shared_ptr<vector<int> > hits(new vector<int>);
+ boost::shared_ptr<vector<struct pollfd> > hits(new vector<struct pollfd>);
int ret = poll(fds, limit, _timeout);
-
- for (int i = 0; i<limit; i++) {
- if (fds[i].revents == POLLIN) {
- hits->push_back(i);
- // If we got as many matches as were seen by poll(), then
- // stop searching the rest of the items in the array.
- if (hits->size() == ret) {
- break;
- }
+
+ log_debug("Poll returned: %d, timeout is: %d", ret, _timeout);
+
+ while (ret--) {
+ for (int i = 0; i<limit; i++) {
+ // If we get this event, the other end of the connection has been
shut down
+#if 0
+ if (fds[i].revents & POLLERR) {
+ log_debug("Revents has a set %d", fds[i].revents);
+ }
+ if (fds[i].revents & POLLHUP) {
+ log_debug("Revents has a POLLHUP set %d", fds[i].revents);
+ }
+ if (fds[i].revents & POLLNVAL) {
+ log_debug("Revents has a POLLNVAL set %d", fds[i].revents);
+// throw GnashException("Polling an invalid file descritor");
+ }
+ if (fds[i].revents & POLLIN) {
+ log_debug("Revents has a POLLIN set %d", fds[i].revents);
+ }
+ if (fds[i].revents & POLLMSG) {
+ log_debug("Revents has a POLLMSG set %d", fds[i].revents);
+ }
+ if (fds[i].revents & POLLREMOVE) {
+ log_debug("Revents has a POLLREMOVE set %d", fds[i].revents);
+ }
+ if (fds[i].revents & POLLRDHUP) {
+ log_debug("Revents has a POLLRDHUP set %d", fds[i].revents);
+// throw GnashException("Connection dropped from client side.");
+ }
+#endif
+// if ((fds[i].revents & POLLIN) || (fds[i].revents & POLLRDHUP)) {
+ hits->push_back(fds[i]);
+// // If we got as many matches as were seen by poll(), then
+// // stop searching the rest of the items in the array.
+// if (hits->size() == ret) {
+// break;
+// }
+// } else {
+// log_debug("No data on fd #%d, revents is %d", fds[i].fd,
fds[i].revents);
+// }
}
}
-
+
return hits;
}
fd_set
Network::waitForNetData(vector<int> &data)
{
-// GNASH_REPORT_FUNCTION;
+ GNASH_REPORT_FUNCTION;
fd_set fdset;
FD_ZERO(&fdset);
@@ -987,10 +1021,9 @@
}
fd_set
-//boost::shared_ptr<vector<int> >
Network::waitForNetData(int limit, fd_set files)
{
-// GNASH_REPORT_FUNCTION;
+ GNASH_REPORT_FUNCTION;
// select modifies this the set of file descriptors, and we don't
// want to modify the one passed as an argument, so we make a copy.
@@ -1032,6 +1065,26 @@
return fdset;
}
+Network &
+Network::operator = (Network &net)
+{
+ GNASH_REPORT_FUNCTION;
+
+ // the file descriptor used for reading and writing
+ _sockfd= net.getFileFd();
+ // the file descriptor used to listen for new connections
+ _listenfd = net.getListenFd();
+ _port = net.getPort();
+ _portstr = net.getPortStr();
+ _url = net.getURL();
+ _protocol = net.getProtocol();
+ _host = net.getHost();
+ _path = net.getPath();
+ _connected = net.connected();
+ _debug = net.netDebug();
+ _timeout = net.getTimeout();
+}
+
void
Network::toggleDebug(bool val)
{
=== modified file 'libnet/network.h'
--- a/libnet/network.h 2008-11-01 15:00:27 +0000
+++ b/libnet/network.h 2008-11-06 22:41:17 +0000
@@ -48,22 +48,14 @@
#include <vector>
#include <cassert>
#include <string>
-
-// /// \struct pollfd
-// ///
-// /// We use the system call poll()s data structure for passing
-// #ifndef HAVE_POLL
-// struct pollfd {
-// int fd; // the relevant file descriptor
-// short events; // events we are interested in
-// short revents; // events which occur will be marked here
-// };
-// #endif
+#include <map>
namespace amf {
class Buffer;
}
+/// \namespace gnash
+/// This is the main namespace for Gnash and it's libraries.
namespace gnash {
// Define the ports for the RTMP protocols
@@ -89,6 +81,10 @@
const size_t NETBUFSIZE = 1448; // 1500 appears to be the default size
as used by FMS
//const size_t NETBUFSIZE = 1357*2; // 1500 appears to be the default size
as used by FMS
+/// \class Network
+/// This is a low level network class for Gnash and Cygnal. This
+/// handles the grunt work on both the client side and the server
+/// side of a network connection.
class DSOEXPORT Network {
public:
typedef boost::uint8_t byte_t;
@@ -96,27 +92,62 @@
Network();
~Network();
- // Create a new server. After creating it, then you have to wait
- // for an incoming connection.
+ /// \brief Create a new server.
+ /// After creating it, then you have to wait for an
+ /// incoming connection.
+ ///
+ /// @param port The optional port number to wait on for
+ /// connections.
+ ///
+ /// @return The file descritor to wait for connections on.
int createServer(void);
int createServer(short port);
- // Accept a client connection for the current server.
+ /// \brief Accept a client connection for the current server.
+ ///
+ /// @param fd The optional file descriptor to wait on for
+ /// connections.
+ ///
+ /// @param block True if this should be a blocking wait.
+ ///
+ /// @return The file descriptor of the new connection.
int newConnection(void);
int newConnection(int fd);
int newConnection(bool block, int fd);
int newConnection(bool block);
- // Connect to a named pipe
+ /// \brief Connect to a named pipe
+ ///
+ ///
+ /// @param sock The name of the named pipe to connect to.
+ ///
+ /// @return True if the connect suceeded, false if it failed.
bool connectSocket(const std::string &sock);
- // Create a client connection to a tcp/ip server
+ /// \brief Create a client connection to a tcp/ip server.
+ ///
+ /// @param port The tcp/ip port to use for contacting the server.
+ ///
+ /// @param hostname The name of the host to connect to. The
+ /// default is localhost.
+ ///
+ /// @return True if the connect suceeded, false if it failed.
bool createClient(void);
bool createClient(short port);
bool createClient(const std::string &hostname);
bool createClient(const std::string &hostname, short port);
- // Read from the connection
+ /// \brief Read from the opened connection.
+ ///
+ /// @param buffer A Buffer class to hold the data.
+ ///
+ /// @param timeout An optional timeout value for reading data.
+ ///
+ /// @param fd The optional file descriptor to read data from.
+ ///
+ /// @param nbytes The number of bytes to try to read.
+ ///
+ /// @return The number of bytes read.
amf::Buffer *readNet();
int readNet(amf::Buffer *buffer);
int readNet(amf::Buffer *buffer, int timeout);
@@ -125,7 +156,17 @@
int readNet(int fd, byte_t *buffer, int nbytes);
int readNet(int fd, byte_t *buffer, int nbytes, int timeout);
- // Write to the connection
+ /// \brief Write to the opened connection.
+ ///
+ /// @param buffer A Buffer class holding the data.
+ ///
+ /// @param timeout An optional timeout value for writing data.
+ ///
+ /// @param fd The optional file descriptor to write data to from.
+ ///
+ /// @param nbytes The number of bytes to try to write..
+ ///
+ /// @return The number of bytes read.
int writeNet(amf::Buffer *buffer);
int writeNet(const std::string &buffer);
int writeNet(const byte_t *buffer, int nbytes);
@@ -134,12 +175,16 @@
int writeNet(int fd, const byte_t *buffer, int nbytes, int timeout);
#ifdef HAVE_POLL
- boost::shared_ptr<std::vector<int> > waitForNetData(int limit, struct
pollfd *fds);
+ boost::shared_ptr<std::vector<struct pollfd> > waitForNetData(int limit,
struct pollfd *fds);
#endif
fd_set waitForNetData(int limit, fd_set data);
fd_set waitForNetData(std::vector<int> &data);
- // Close the connection
+ /// \brief Close the connection
+ ///
+ /// @param fd The file descritor of the open connection to close.
+ ///
+ /// @return True if the connection was closed, false if it failed.
bool closeNet();
bool closeNet(int fd);
bool closeConnection();
@@ -169,10 +214,10 @@
const std::string& getHost() const { return _host; }
const std::string& getPortStr() const { return _portstr; }
const std::string& getPath() const { return _path; }
+ void setTimeout(int x) { _timeout = x; }
int getTimeout() const { return _timeout; }
- // Network is not copiable !
- //Network &operator = (Network &net) {}
+ Network &operator = (Network &net);
protected:
in_addr_t _ipaddr;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] /srv/bzr/gnash/rtmp r9708: get waitForNetData() working.,
rob <=