source: vscpl/src/hu/varadiistvan/scpl/io/_win32/LocalConnector.h@ 24:f60eded155f3

Last change on this file since 24:f60eded155f3 was 9:84f0dcb053b4, checked in by István Váradi <ivaradi@…>, 12 years ago

Imported the Win32-specific I/O code

File size: 4.4 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_WIN32_LOCALCONNECTOR_H
30#define HU_VARADIISTVAN_SCPL_IO_WIN32_LOCALCONNECTOR_H
31//------------------------------------------------------------------------------
32
33#include "Completer.h"
34
35#include "LocalSocket.h"
36
37//------------------------------------------------------------------------------
38
39namespace hu { namespace varadiistvan { namespace scpl { namespace io {
40
41//------------------------------------------------------------------------------
42
43/**
44 * A connector that connects to a local server socket (i.e. named
45 * pipe).
46 */
47class LocalConnector : public FailableReference<LocalConnector>
48{
49private:
50 /**
51 * The local socket to connect on behalf of which we connect (it should
52 * actually be a LocalClientSocket).
53 */
54 LocalSocket& socket;
55
56 /**
57 * The path of the pipe to connect to.
58 */
59 char path[256];
60
61 /**
62 * Indicate if we are connected.
63 */
64 bool connected;
65
66protected:
67 /**
68 * Construct the connector.
69 */
70 LocalConnector(LocalSocket* socket, const char* name);
71
72public:
73 /**
74 * Connect to an address properly set up.
75 *
76 * If the connection succeeds immediately, it indicates success.
77 *
78 * If the connection does not succeed, because it would block, it
79 * sets up the socket to wait for the connection to succeed, and
80 * returns failure.
81 *
82 * If the connection fails for another reason, the error code is
83 * set, and false is returned.
84 */
85 bool connect();
86
87private:
88 /**
89 * Get the failable object.
90 */
91 const Failable& getFailable() const;
92
93 /**
94 * Get the failable object.
95 */
96 Failable& getFailable();
97
98 friend class FailableReference<LocalConnector>;
99 friend class LocalClientSocket;
100};
101
102//------------------------------------------------------------------------------
103// Inline definitions
104//------------------------------------------------------------------------------
105
106inline LocalConnector::LocalConnector(LocalSocket* socket, const char* name) :
107 socket(*socket),
108 connected(false)
109{
110 LocalSocket::setupPath(path, name);
111}
112
113//------------------------------------------------------------------------------
114
115inline const Failable& LocalConnector::getFailable() const
116{
117 return socket;
118}
119
120//------------------------------------------------------------------------------
121
122inline Failable& LocalConnector::getFailable()
123{
124 return socket;
125}
126
127//------------------------------------------------------------------------------
128
129} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
130
131//------------------------------------------------------------------------------
132#endif // HU_VARADIISTVAN_SCPL_IO_WIN32_LOCALCONNECTOR_H
133
134// Local Variables:
135// mode: C++
136// c-basic-offset: 4
137// indent-tabs-mode: nil
138// End:
Note: See TracBrowser for help on using the repository browser.