feisty meow concerns codebase  2.140
socket_data.h
Go to the documentation of this file.
1 #ifndef SOCKET_DATA_CLASS
2 #define SOCKET_DATA_CLASS
3 
4 /*****************************************************************************\
5 * *
6 * Name : socket_data *
7 * Author : Chris Koeritz *
8 * *
9 * Purpose: *
10 * *
11 * Tracks the partially transmitted data for transports based on a socket *
12 * metaphor, where a socket is merely a numerical designation of the channel. *
13 * Note: this is a heavy-weight header. don't include it in other headers. *
14 * *
15 *******************************************************************************
16 * Copyright (c) 1991-$now By Author. This program is free software; you can *
17 * redistribute it and/or modify it under the terms of the GNU General Public *
18 * License as published by the Free Software Foundation; either version 2 of *
19 * the License or (at your option) any later version. This is online at: *
20 * http://www.fsf.org/copyleft/gpl.html *
21 * Please send any updates to: fred@gruntose.com *
22 \*****************************************************************************/
23 
24 #include <basis/astring.h>
25 #include <basis/byte_array.h>
26 #include <basis/astring.h>
27 #include <timely/time_stamp.h>
28 
29 namespace sockets {
30 
32 {
33 public:
34  int _socket; // the number of the socket we are managing here.
35  basis::byte_array _partially_sent; // accumulates bytes from partial sends.
36  basis::byte_array _partially_received; // accumulates bytes from partial receives.
37  basis::byte_array _receive_buffer; // temporary that's used for reading.
38  bool _is_server; // true if this socket is for a server.
40  // the events being watched for on this socket. the bitwise or'ed items
41  // in this are from the socket_interests enum.
43  // true if a connect or accept is pending. the default is true since we
44  // do not want to try probing the socket until it has been connected, for
45  // sockets in connected mode.
46  int _server_socket; // non-zero if socket was accepted on root server socket.
47  bool _connected_mode; // true if this is a connected type of socket.
49  // when the connection was last given a check for a connected state.
50 
51  socket_data(int socket = 0, bool server = true, int server_socket = 0,
52  bool connected_mode = true)
54  _connection_pending(true), _server_socket(server_socket),
55  _connected_mode(connected_mode) {}
57 
58  bool server() const { return _is_server; }
59  bool client() const { return !_is_server; }
60 
61  basis::astring text_form() const;
62  // returns a descriptive list of the data contained here.
63 };
64 
66 
67 // implementations.
68 
70 {
71  return basis::a_sprintf("socket=%d, type=%s, send_pend=%d, recv_pend=%d, "
72  "interests=%s, conn_pending=%s",
73  _socket, _is_server? "server":"client", _partially_sent.length(),
76  _connection_pending? "true":"false");
77 }
78 
79 } //namespace.
80 
81 #endif
82 
a_sprintf is a specialization of astring that provides printf style support.
Definition: astring.h:440
int length() const
Returns the current reported length of the allocated C array.
Definition: array.h:115
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
const char * s() const
synonym for observe. the 's' stands for "string", if that helps.
Definition: astring.h:113
A very common template for a dynamic array of bytes.
Definition: byte_array.h:36
static basis::astring interest_name(int to_name)
Definition: raw_socket.cpp:111
socket_data(int socket=0, bool server=true, int server_socket=0, bool connected_mode=true)
Definition: socket_data.h:51
basis::astring text_form() const
Definition: socket_data.h:69
basis::byte_array _receive_buffer
Definition: socket_data.h:37
basis::byte_array _partially_received
Definition: socket_data.h:36
bool client() const
Definition: socket_data.h:59
timely::time_stamp _last_conn_alert
Definition: socket_data.h:48
bool server() const
Definition: socket_data.h:58
basis::byte_array _partially_sent
Definition: socket_data.h:35
Represents a point in time relative to the operating system startup time.
Definition: time_stamp.h:38
Provides access to the operating system's socket methods.
Definition: base_address.h:26