source: vscpl/src/hu/varadiistvan/scpl/io/_posix/ClientSocket.h@ 33:ba64bedf956d

Last change on this file since 33:ba64bedf956d was 8:7b2598d1ea55, checked in by István Váradi <ivaradi@…>, 12 years ago

Imported the I/O library for POSIX and the pseudo-random generator

File size: 4.3 KB
Line 
1// Copyright (c) 2013 by István Váradi
2
3// This file is part of VSCPL, a simple cross-platform utility library
4
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are met:
7
8// 1. Redistributions of source code must retain the above copyright notice, this
9// list of conditions and the following disclaimer.
10// 2. Redistributions in binary form must reproduce the above copyright notice,
11// this list of conditions and the following disclaimer in the documentation
12// and/or other materials provided with the distribution.
13
14// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
25// The views and conclusions contained in the software and documentation are those
26// of the authors and should not be interpreted as representing official policies,
27// either expressed or implied, of the FreeBSD Project.
28
29#ifndef HU_VARADIISTVAN_SCPL_IO_POSIX_CLIENTSOCKET_H
30#define HU_VARADIISTVAN_SCPL_IO_POSIX_CLIENTSOCKET_H
31//------------------------------------------------------------------------------
32
33#include "Socket.h"
34
35//------------------------------------------------------------------------------
36
37namespace hu { namespace varadiistvan { namespace scpl { namespace io {
38
39//------------------------------------------------------------------------------
40
41class Connector;
42
43//------------------------------------------------------------------------------
44
45/**
46 * A socket that can be connected to another one.
47 */
48class ClientSocket : public Socket
49{
50private:
51 /**
52 * The connector.
53 */
54 Connector& connector;
55
56protected:
57 /**
58 * Construct the socket with the given parameters.
59 */
60 ClientSocket(int domain, int type, Connector& connector,
61 Waiter* waiter = 0, int protocol = 0,
62 size_t readingCapacity = DEFAULT_CAPACITY,
63 size_t writingCapacity = DEFAULT_CAPACITY);
64
65protected:
66 /**
67 * Handle any events on the file descriptor. If a connection is in
68 * progress, and the incoming events have the EPOLLOUT flag set,
69 * the connector is called to handle the event. Then the parent
70 * class' handleEvents function is called.
71 */
72 virtual void handleEvents(short events);
73
74 /**
75 * Connect the socket to the given address.
76 *
77 * @return whether the connection succeeded or not. If it does not
78 * succeeded, it may be either because of the socket being
79 * non-blocking and some time is needed, or because of a failure,
80 * in which case the error code will be set properly.
81 */
82 bool connect(const struct sockaddr* addr, size_t addrlen);
83
84 friend class Connector;
85};
86
87//------------------------------------------------------------------------------
88// Inline definitions
89//------------------------------------------------------------------------------
90
91inline ClientSocket::ClientSocket(int domain, int type, Connector& connector,
92 Waiter* waiter, int protocol,
93 size_t readingCapacity,
94 size_t writingCapacity) :
95 Socket(domain, type, waiter, protocol, readingCapacity, writingCapacity),
96 connector(connector)
97{
98}
99
100//------------------------------------------------------------------------------
101
102} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
103
104//------------------------------------------------------------------------------
105#endif // HU_VARADIISTVAN_SCPL_IO_POSIX_CLIENTSOCKET_H
106
107// Local Variables:
108// mode: C++
109// c-basic-offset: 4
110// indent-tabs-mode: nil
111// End:
Note: See TracBrowser for help on using the repository browser.