• 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 CRPC_NET_H
17 #define CRPC_NET_H
18 
19 #include "common.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 /**
26  * @Description Open/close fd flag O_NONBLOCK
27  *
28  * @param fd - Socket fd
29  * @param type - 1 open O_NONBLOCK; other close O_NONBLOCK
30  * @return int - 0 Success; -1 Failed
31  */
32 int SetNonBlock(int fd, int type);
33 
34 /**
35  * @Description Read fd's message
36  *
37  * @param fd - Socket fd
38  * @param buf - Buffer for storing the read content
39  * @param count - Specifies the number of records to be read
40  * @return int - return read message numbers or read error return error code
41  */
42 int MyRead(int fd, char *buf, int count);
43 
44 /**
45  * @Description Write to fd
46  *
47  * @param fd - Socket fd
48  * @param buf - Contents to write to the file
49  * @param count - Size of the contents to write to the file
50  * @return int - return write message numbers or write error return error code
51  */
52 int MyWrite(int fd, const char *buf, int count);
53 
54 /**
55  * @Description Create a Unix Server
56  *
57  * @param path - Location of the domain socket communication file
58  * @param backlog - Maximum number of connections that can be queued by a socket
59  * @return int - -1 failed; else return server listen fd
60  */
61 int CreateUnixServer(const char *path, int backlog);
62 
63 /**
64  * @Description Connect to Unix Server
65  *
66  * @param path - Location of the domain socket communication file
67  * @return int - -1 failed; else return client socket fd
68  */
69 int ConnectUnixServer(const char *path);
70 
71 /**
72  * @Description Waiting for socket events to occur
73  *
74  * @param fd - socket fd
75  * @param mask - event mask
76  * @param milliseconds - max Waiting time
77  * @return int - -1 Failed; 0 Time out; 1 events occurred
78  */
79 int WaitFdEvent(int fd, unsigned int mask, int milliseconds);
80 
81 #ifdef __cplusplus
82 }
83 #endif
84 #endif