xref: /aosp_15_r20/external/deqp/execserver/xsTcpServer.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker #ifndef _XSTCPSERVER_HPP
2*35238bceSAndroid Build Coastguard Worker #define _XSTCPSERVER_HPP
3*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program Execution Server
5*35238bceSAndroid Build Coastguard Worker  * ---------------------------------------------
6*35238bceSAndroid Build Coastguard Worker  *
7*35238bceSAndroid Build Coastguard Worker  * Copyright 2014 The Android Open Source Project
8*35238bceSAndroid Build Coastguard Worker  *
9*35238bceSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
10*35238bceSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
11*35238bceSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
12*35238bceSAndroid Build Coastguard Worker  *
13*35238bceSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
14*35238bceSAndroid Build Coastguard Worker  *
15*35238bceSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
16*35238bceSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
17*35238bceSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18*35238bceSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
19*35238bceSAndroid Build Coastguard Worker  * limitations under the License.
20*35238bceSAndroid Build Coastguard Worker  *
21*35238bceSAndroid Build Coastguard Worker  *//*!
22*35238bceSAndroid Build Coastguard Worker  * \file
23*35238bceSAndroid Build Coastguard Worker  * \brief TCP Server.
24*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
25*35238bceSAndroid Build Coastguard Worker 
26*35238bceSAndroid Build Coastguard Worker #include "xsDefs.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "deSocket.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "deThread.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "deMutex.hpp"
30*35238bceSAndroid Build Coastguard Worker 
31*35238bceSAndroid Build Coastguard Worker #include <vector>
32*35238bceSAndroid Build Coastguard Worker 
33*35238bceSAndroid Build Coastguard Worker namespace xs
34*35238bceSAndroid Build Coastguard Worker {
35*35238bceSAndroid Build Coastguard Worker 
36*35238bceSAndroid Build Coastguard Worker class ConnectionHandler;
37*35238bceSAndroid Build Coastguard Worker 
38*35238bceSAndroid Build Coastguard Worker class TcpServer
39*35238bceSAndroid Build Coastguard Worker {
40*35238bceSAndroid Build Coastguard Worker public:
41*35238bceSAndroid Build Coastguard Worker     TcpServer(deSocketFamily family, int port);
42*35238bceSAndroid Build Coastguard Worker     virtual ~TcpServer(void);
43*35238bceSAndroid Build Coastguard Worker 
44*35238bceSAndroid Build Coastguard Worker     virtual ConnectionHandler *createHandler(de::Socket *socket, const de::SocketAddress &clientAddress) = DE_NULL;
45*35238bceSAndroid Build Coastguard Worker 
46*35238bceSAndroid Build Coastguard Worker     virtual void runServer(void);
47*35238bceSAndroid Build Coastguard Worker     void stopServer(void);
48*35238bceSAndroid Build Coastguard Worker 
49*35238bceSAndroid Build Coastguard Worker     virtual void connectionDone(ConnectionHandler *handler);
50*35238bceSAndroid Build Coastguard Worker 
51*35238bceSAndroid Build Coastguard Worker protected:
52*35238bceSAndroid Build Coastguard Worker     de::Socket m_socket;
53*35238bceSAndroid Build Coastguard Worker 
54*35238bceSAndroid Build Coastguard Worker private:
55*35238bceSAndroid Build Coastguard Worker     TcpServer(const TcpServer &other);
56*35238bceSAndroid Build Coastguard Worker     TcpServer &operator=(const TcpServer &other);
57*35238bceSAndroid Build Coastguard Worker 
58*35238bceSAndroid Build Coastguard Worker     void addLiveConnection(ConnectionHandler *handler);
59*35238bceSAndroid Build Coastguard Worker     void deleteDoneConnections(void);
60*35238bceSAndroid Build Coastguard Worker 
61*35238bceSAndroid Build Coastguard Worker     de::Mutex m_connectionListLock;
62*35238bceSAndroid Build Coastguard Worker     std::vector<ConnectionHandler *> m_liveConnections;
63*35238bceSAndroid Build Coastguard Worker     std::vector<ConnectionHandler *> m_doneConnections;
64*35238bceSAndroid Build Coastguard Worker };
65*35238bceSAndroid Build Coastguard Worker 
66*35238bceSAndroid Build Coastguard Worker class ConnectionHandler : public de::Thread
67*35238bceSAndroid Build Coastguard Worker {
68*35238bceSAndroid Build Coastguard Worker public:
ConnectionHandler(TcpServer * server,de::Socket * socket)69*35238bceSAndroid Build Coastguard Worker     ConnectionHandler(TcpServer *server, de::Socket *socket) : m_server(server), m_socket(socket)
70*35238bceSAndroid Build Coastguard Worker     {
71*35238bceSAndroid Build Coastguard Worker     }
72*35238bceSAndroid Build Coastguard Worker     virtual ~ConnectionHandler(void);
73*35238bceSAndroid Build Coastguard Worker 
74*35238bceSAndroid Build Coastguard Worker     void run(void);
75*35238bceSAndroid Build Coastguard Worker 
76*35238bceSAndroid Build Coastguard Worker protected:
77*35238bceSAndroid Build Coastguard Worker     virtual void handle(void) = DE_NULL;
78*35238bceSAndroid Build Coastguard Worker 
79*35238bceSAndroid Build Coastguard Worker protected:
80*35238bceSAndroid Build Coastguard Worker     TcpServer *m_server;
81*35238bceSAndroid Build Coastguard Worker     de::Socket *m_socket;
82*35238bceSAndroid Build Coastguard Worker };
83*35238bceSAndroid Build Coastguard Worker 
84*35238bceSAndroid Build Coastguard Worker } // namespace xs
85*35238bceSAndroid Build Coastguard Worker 
86*35238bceSAndroid Build Coastguard Worker #endif // _XSTCPSERVER_HPP
87