Instrument Neutral Distributed Interface INDI
2.0.2
integs
ServerMock.cpp
Go to the documentation of this file.
1
/*******************************************************************************
2
Copyright(c) 2022 Ludovic Pollet. All rights reserved.
3
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License version 2 as published by the Free Software Foundation.
7
8
This library is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
Library General Public License for more details.
12
13
You should have received a copy of the GNU Library General Public License
14
along with this library; see the file COPYING.LIB. If not, write to
15
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
Boston, MA 02110-1301, USA.
17
*******************************************************************************/
18
19
#include <unistd.h>
20
#include <stdexcept>
21
22
#include "
IndiClientMock.h
"
23
#include "
ServerMock.h
"
24
#include "
utils.h
"
25
26
27
ServerMock::ServerMock
()
28
{
29
fd = -1;
30
}
31
32
ServerMock::~ServerMock
()
33
{
34
close
();
35
}
36
37
void
ServerMock::close
()
38
{
39
if
(fd != -1)
40
{
41
::close
(fd);
42
fd = -1;
43
}
44
}
45
46
47
// Start the listening socket that will receive driver upon their starts
48
void
ServerMock::listen
(
int
tcpPort)
49
{
50
close
();
51
fd =
tcpSocketListen
(tcpPort);
52
}
53
54
void
ServerMock::listen
(
const
std::string &unixPath)
55
{
56
close
();
57
fd =
unixSocketListen
(unixPath);
58
}
59
60
void
ServerMock::accept
(
IndiClientMock
&into)
61
{
62
if
(fd == -1)
63
{
64
throw
std::runtime_error(
"Accept called on non listening server"
);
65
}
66
int
child =
socketAccept
(fd);
67
into.
associate
(child);
68
}
IndiClientMock.h
ServerMock.h
IndiClientMock
Definition:
IndiClientMock.h:32
IndiClientMock::associate
void associate(int fd)
Definition:
IndiClientMock.cpp:73
ServerMock::listen
void listen(int tcpPort)
Definition:
ServerMock.cpp:48
ServerMock::~ServerMock
virtual ~ServerMock()
Definition:
ServerMock.cpp:32
ServerMock::close
void close()
Definition:
ServerMock.cpp:37
ServerMock::accept
void accept(IndiClientMock &into)
Definition:
ServerMock.cpp:60
ServerMock::ServerMock
ServerMock()
Definition:
ServerMock.cpp:27
socketAccept
int socketAccept(int fd)
Definition:
utils.cpp:144
unixSocketListen
int unixSocketListen(const std::string &unixAddr)
Definition:
utils.cpp:71
tcpSocketListen
int tcpSocketListen(int port)
Definition:
utils.cpp:108
utils.h
Generated on Sat May 13 2023 14:24:24 for Instrument Neutral Distributed Interface INDI by
1.9.1