libassa 3.5.1
Loading...
Searching...
No Matches
IPv4Socket.h
Go to the documentation of this file.
1// -*- c++ -*-
2//------------------------------------------------------------------------------
3// IPv4Socket.h
4//------------------------------------------------------------------------------
5// Copyright (c) 1998 by Vladislav Grinchenko
6//
7// This library is free software; you can redistribute it and/or
8// modify it under the terms of the GNU Library General Public
9// License as published by the Free Software Foundation; either
10// version 2 of the License, or (at your option) any later version.
11//------------------------------------------------------------------------------
12#ifndef IPV4_SOCKET_Hh
13#define IPV4_SOCKET_Hh
14
15#include "assa/Socket.h"
16#include "assa/Socketbuf.h"
17
24namespace ASSA {
25class IPv4Socket : public Socket
26{
27public:
29 static const int MAXTCPBUFSZ;
30
33 : m_path (0), m_rdbuf (new Socketbuf (this)) {
34 trace_with_mask("IPv4Socket::IPv4Socket()",SOCKTRACE);
35 }
36
42 {
43 trace_with_mask("IPv4Socket::IPv4Socket(fd_)",SOCKTRACE);
44
45 m_fd = fd_; // inherited from the parent class
46 }
47
50 {
51 trace_with_mask("IPv4Socket::~IPv4Socket",SOCKTRACE);
52 this->close ();
53
54 if (m_rdbuf != 0) {
55 delete m_rdbuf;
56 }
57 }
58
64 IPv4Socket* clone () const;
65
66
74 bool open(const int domain_);
75
79 bool close();
80
90 bool connect(const Address& address_);
91
99 virtual bool bind (const Address& my_address_);
100
111 IPv4Socket* accept ();
112
123 int read (char* buf_, const unsigned int size_);
124
131 int write (const char* buf_, const unsigned int size_);
132
133
135 handler_t getHandler () const { return m_fd; }
136
138 const int getDomain () const { return m_type; }
139
146 virtual Streambuf* rdbuf () { return m_rdbuf; }
147
155 virtual Streambuf* rdbuf (Streambuf* sb_);
156
162 virtual int in_avail () const { return m_rdbuf->in_avail (); }
163
164private:
165 // No copying
168
169private:
171
173 char* m_path;
174
177};
178
179} // end namespace ASSA
180
181#endif // IPV4_SOCKET_Hh
182
183
184
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
Definition Logger.h:437
Abstraction of socket data type.
Socketbuf class is derived from Streambuf to provide I/O with the socket file descriptor.
A wrapper class to provide AutoPtr with reference semantics.
Definition AutoPtr.h:32
IPv4Socket * accept()
Accept connection on the listening socket.
int write(const char *buf_, const unsigned int size_)
Perform blocking write by writing packet of specified size.
IPv4Socket(const handler_t fd_)
Constructor from file descriptor.
Definition IPv4Socket.h:40
IPv4Socket()
Default constructor.
Definition IPv4Socket.h:32
IPv4Socket * clone() const
"Virtual constructor".
virtual Streambuf * rdbuf()
Return a pointer to the Socketbuf associated with the stream.
Definition IPv4Socket.h:146
bool close()
Close socket connection.
bool connect(const Address &address_)
Client makes connection with the server at address_.
bool open(const int domain_)
Create socket.
Streambuf * m_rdbuf
Socketbuf.
Definition IPv4Socket.h:176
virtual int in_avail() const
This function returns the number of characters immediately available in the get area of the underlyin...
Definition IPv4Socket.h:162
virtual bool bind(const Address &my_address_)
Server binds listening socket to its local well-known port.
const int getDomain() const
Get socket domain type.
Definition IPv4Socket.h:138
IPv4Socket(const IPv4Socket &)
int read(char *buf_, const unsigned int size_)
Read packet of specified size and save it to the given buffer.
handler_t getHandler() const
Get socket file descriptor.
Definition IPv4Socket.h:135
char * m_path
Path of UNIX domain socket.
Definition IPv4Socket.h:173
IPv4Socket & operator=(const IPv4Socket &)
~IPv4Socket()
Destructor will close connection.
Definition IPv4Socket.h:49
static const int MAXTCPBUFSZ
Maximum TCP data frame (no options)
Definition IPv4Socket.h:29
int m_type
Socket domain type.
Definition Socket.h:488
handler_t m_fd
File descriptor.
Definition Socket.h:485
Streambuf class.
Definition Streambuf.h:91
int in_avail()
This function returns the number of characters immediately available in the get area.
Definition Streambuf.h:399
@ SOCKTRACE
Extended Socket & friends messages
Definition LogMask.h:42