blob: 20c67cc695e1733036b38e2610e944ef99e5a6fa [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001/**
2 * Copyright (C) ARM Limited 2010-2014. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9#ifndef __OLY_SOCKET_H__
10#define __OLY_SOCKET_H__
11
12#include <stddef.h>
13
14class OlySocket {
15public:
16#ifndef WIN32
17 static int connect(const char* path, const size_t pathSize);
18#endif
19
20 OlySocket(int socketID);
21 ~OlySocket();
22
23 void closeSocket();
24 void shutdownConnection();
25 void send(const char* buffer, int size);
26 int receive(char* buffer, int size);
27 int receiveNBytes(char* buffer, int size);
28 int receiveString(char* buffer, int size);
29
30 bool isValid() const { return mSocketID >= 0; }
31
32private:
33 int mSocketID;
34};
35
36class OlyServerSocket {
37public:
38 OlyServerSocket(int port);
39#ifndef WIN32
40 OlyServerSocket(const char* path, const size_t pathSize);
41#endif
42 ~OlyServerSocket();
43
44 int acceptConnection();
45 void closeServerSocket();
46
47 int getFd() { return mFDServer; }
48
49private:
50 int mFDServer;
51
52 void createServerSocket(int port);
53};
54
55#endif //__OLY_SOCKET_H__