socket_data.h

Go to the documentation of this file.
00001 #ifndef SOCKET_DATA_CLASS
00002 #define SOCKET_DATA_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : socket_data                                                       *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *  Purpose:                                                                   *
00010 *                                                                             *
00011 *    Tracks the partially transmitted data for transports based on a socket   *
00012 *  metaphor, where a socket is merely a numerical designation of the channel. *
00013 *    Note: this is a heavy-weight header.  don't include it in other headers. *
00014 *                                                                             *
00015 *******************************************************************************
00016 * Copyright (c) 1991-$now By Author.  This program is free software; you can  *
00017 * redistribute it and/or modify it under the terms of the GNU General Public  *
00018 * License as published by the Free Software Foundation; either version 2 of   *
00019 * the License or (at your option) any later version.  This is online at:      *
00020 *     http://www.fsf.org/copyleft/gpl.html                                    *
00021 * Please send any updates to: fred@gruntose.com                               *
00022 \*****************************************************************************/
00023 
00024 #include <basis/astring.h>
00025 #include <basis/byte_array.h>
00026 #include <basis/astring.h>
00027 #include <timely/time_stamp.h>
00028 
00029 namespace sockets {
00030 
00031 class socket_data
00032 {
00033 public:
00034   int _socket;  // the number of the socket we are managing here.
00035   basis::byte_array _partially_sent;  // accumulates bytes from partial sends.
00036   basis::byte_array _partially_received;  // accumulates bytes from partial receives.
00037   basis::byte_array _receive_buffer;  // temporary that's used for reading.
00038   bool _is_server;  // true if this socket is for a server.
00039   int _registered_interests;
00040     // the events being watched for on this socket.  the bitwise or'ed items
00041     // in this are from the socket_interests enum.
00042   bool _connection_pending;
00043     // true if a connect or accept is pending.  the default is true since we
00044     // do not want to try probing the socket until it has been connected, for
00045     // sockets in connected mode.
00046   int _server_socket;  // non-zero if socket was accepted on root server socket.
00047   bool _connected_mode;  // true if this is a connected type of socket.
00048   timely::time_stamp _last_conn_alert;
00049     // when the connection was last given a check for a connected state.
00050 
00051   socket_data(int socket = 0, bool server = true, int server_socket = 0,
00052       bool connected_mode = true)
00053       : _socket(socket), _is_server(server), _registered_interests(0),
00054         _connection_pending(true), _server_socket(server_socket),
00055         _connected_mode(connected_mode) {}
00056   ~socket_data() {}
00057 
00058   bool server() const { return _is_server; }
00059   bool client() const { return !_is_server; }
00060 
00061   basis::astring text_form() const;
00062     // returns a descriptive list of the data contained here.
00063 };
00064 
00066 
00067 // implementations.
00068 
00069 basis::astring socket_data::text_form() const
00070 {
00071   return basis::a_sprintf("socket=%d, type=%s, send_pend=%d, recv_pend=%d, "
00072       "interests=%s, conn_pending=%s",
00073       _socket, _is_server? "server":"client", _partially_sent.length(),
00074       _partially_received.length(),
00075       raw_socket::interest_name(_registered_interests).s(),
00076       _connection_pending? "true":"false");
00077 }
00078 
00079 } //namespace.
00080 
00081 #endif
00082 
Generated on Sat Jan 28 04:22:43 2012 for hoople2 project by  doxygen 1.6.3