• 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 NSTACKX_SOCKET_H
17 #define NSTACKX_SOCKET_H
18 
19 #include "sys_common_header.h"
20 #include "nstackx_common_header.h"
21 
22 typedef enum SocketProtocol {
23     NSTACKX_PROTOCOL_TCP = 0,
24     NSTACKX_PROTOCOL_UDP,
25     NSTACKX_PROTOCOL_D2D
26 } SocketProtocol;
27 
28 typedef struct Socket {
29     SocketProtocol protocol;
30     uint8_t isServer;
31     SocketDesc sockfd;
32     struct sockaddr_in dstAddr;
33     struct sockaddr_in srcAddr;
34 } Socket;
35 
36 int32_t SocketModuleInit(void);
37 void SocketModuleClean(void);
38 int32_t SetSocketNonBlock(SocketDesc fd);
39 int32_t SocketOpInProgress(void);
40 int32_t SocketOpWouldBlock(void);
41 int32_t CheckSocketError(void);
42 Socket *ClientSocket(SocketProtocol protocol, const struct sockaddr_in *sockAddr);
43 Socket *ServerSocket(SocketProtocol protocol, const struct sockaddr_in *sockAddr);
44 void CloseSocket(Socket *socket);
45 Socket *AcceptSocket(Socket *serverSocket);
46 int32_t SocketSend(const Socket *socket, const uint8_t *buffer, size_t length);
47 int32_t SocketSendEx(const Socket *socket, uint16_t mss, const struct iovec *iov, uint32_t cnt);
48 void CheckGSOSupport(void);
49 int32_t SupportGSO(void);
50 int32_t SocketRecv(Socket *socket, uint8_t *buffer, size_t length, struct sockaddr_in *srcAddr,
51                    const socklen_t *addrLen);
52 Socket *ClientSocketWithTargetDev(SocketProtocol protocol, const struct sockaddr_in *sockAddr,
53                                   const char *localInterface);
54 
55 #endif  /* NSTACKX_SOCKET_H */
56