1 /*
2 * Copyright (C) 2022 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 #include "spunge.h"
17
18 #include "socket_common.h"
19
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 /*
26 Description: g_spunge hold the infos related to send and recv data, Memory
27 resources, epoll resources and instance resources.
28 Value Range: None
29 Access:g_spunge hold the infos related to send and recv data, Memory
30 resources, epoll resources and instance resources.
31 Remarks:
32 */
33 struct Spunge *g_spunge = FILLP_NULL_PTR;
34
SpungeEpollAppRecvOne(struct FtSocket * sock)35 void SpungeEpollAppRecvOne(struct FtSocket *sock)
36 {
37 (void)SYS_ARCH_ATOMIC_DEC(&sock->rcvEvent, 1);
38 }
39
SpungeEpollEventCallback(struct FtSocket * sock,FILLP_INT event,FILLP_INT count)40 void SpungeEpollEventCallback(struct FtSocket *sock, FILLP_INT event, FILLP_INT count)
41 {
42 if (sock == FILLP_NULL_PTR) {
43 FILLP_LOGERR("invalid input params");
44 return;
45 }
46
47 if ((FILLP_UINT32)event & SPUNGE_EPOLLIN) {
48 (void)SYS_ARCH_ATOMIC_INC(&sock->rcvEvent, count);
49 }
50
51 if (((FILLP_UINT32)event & SPUNGE_EPOLLOUT) && (count > 0)) {
52 (void)SYS_ARCH_ATOMIC_SET(&sock->sendEvent, 1);
53 }
54
55 sock->errEvent |= ((FILLP_UINT32)event & (SPUNGE_EPOLLRDHUP | SPUNGE_EPOLLHUP | SPUNGE_EPOLLERR));
56
57 if ((sock->netconn != FILLP_NULL_PTR) && (!sock->netconn->closeSet)) {
58 if (SYS_ARCH_ATOMIC_READ(&sock->epollWaiting) > 0) {
59 EpollEventCallback(sock, (FILLP_UINT32)event);
60 }
61 }
62 }
63
SockSetOsSocket(struct FtSocket * ftSock,struct SockOsSocket * osSock)64 void SockSetOsSocket(struct FtSocket *ftSock, struct SockOsSocket *osSock)
65 {
66 ftSock->netconn->osSocket[SPUNGE_GET_CUR_INSTANCE()->instIndex] = osSock;
67 osSock->reference++;
68 }
69
70 #ifdef __cplusplus
71 }
72 #endif
73