• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef SOCKET_H
17 #define SOCKET_H
18 
19 #include <cstdint>
20 #include <sys/socket.h>
21 #include <sys/uio.h>
22 
23 namespace OHOS {
24 namespace HiviewDFX {
25 class Socket {
26 public:
27     explicit Socket(int socketType);
28     ~Socket();
29     bool CloseHandler();
30     bool SetHandler(int socketHandler);
31     void SetType(uint32_t socketOption);
32     void SetCredential(struct ucred& cred);
33     uid_t GetUid();
34     pid_t GetPid();
35     int GenerateFD();
36     int Create();
37     int Poll();
38     int Write(const char *data, unsigned int len);
39     int WriteAll(const char *data, unsigned int len);
40     int WriteV(const iovec *vec, unsigned int len);
41     int Read(char *buffer, unsigned int len);
42     int Recv(void *buffer, unsigned int bufferLen, int flags = MSG_PEEK);
43 protected:
44     int socketHandler = 0;
45     uint32_t socketType;
46     struct ucred socketCred = { 0 };
47 };
48 } // namespace HiviewDFX
49 } // namespace OHOS
50 #endif /* SOCKET_H */
51