summaryrefslogtreecommitdiffstats
path: root/stacks/lwip_stack/lwip_src/socket/stackx_socket.h
blob: edc0e86b3d3ff54a46ded7da363500cc6bc2492f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
*
* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef STACKX_SOCKET_H
#define STACKX_SOCKET_H
#include "sbr_protocol_api.h"
#include "stackx_spl_share.h"
#include "nstack_log.h"
#include "stackx_pbuf.h"
#include "common_mem_spinlock.h"

#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif

typedef struct
{
    PRIMARY_ADDR struct spl_pbuf *head;
    PRIMARY_ADDR struct spl_pbuf *tail;
    int totalLen;
} sbr_recvbuf_recoder;

/* need fork and recycle */
typedef struct
{
    common_mem_spinlock_t recv_lock;
    common_mem_spinlock_t common_lock;
    PRIMARY_ADDR void *lastdata;
    u32 lastoffset;
    sbr_recvbuf_recoder recoder;
    i32 recv_timeout;
    i32 send_timeout;
    i32 rcvlowat;
    int err;
    u64 block_polling_time;
    i64 extend_member_bit;
} sbr_fd_share;

/* check sbr_fd_share size */
SIZE_OF_TYPE_NOT_LARGER_THAN_RETURN(sbr_fd_share, SBR_FD_SIZE);

#define sbr_get_fd_share(sk) ((sbr_fd_share*)sk->sk_obj)

#define sbr_get_conn(sk) ((spl_netconn_t*)sk->stack_obj)

#define sbr_get_msg_box(sk) ss_get_msg_box(sbr_get_conn(sk))

/*****************************************************************************
*   Prototype    : sbr_set_sk_errno
*   Description  : set errno for sk
*   Input        : sbr_socket_t * sk
*                  int err
*   Output       : None
*   Return Value : static inline void
*   Calls        :
*   Called By    :
*
*****************************************************************************/
static inline void sbr_set_sk_errno(sbr_socket_t * sk, int err)
{
    sbr_get_fd_share(sk)->err = err;
    if (err != 0)
    {
        if (sbr_get_conn(sk))
        {
            NSSBR_LOGERR("fd=%d,errno=%d,conn=%p,private_data=%p", sk->fd,
                         err, sbr_get_conn(sk),
                         ss_get_private_data(sbr_get_conn(sk)));
        }

        sbr_set_errno(err);
    }
}

/*****************************************************************************
*   Prototype    : sbr_set_sk_io_errno
*   Description  : set errno for sk in send/recv func, in case of too many logs
*   Input        : sbr_socket_t * sk
*                  int err
*   Output       : None
*   Return Value : static inline void
*   Calls        :
*   Called By    :
*
*****************************************************************************/
static inline void sbr_set_sk_io_errno(sbr_socket_t * sk, int err)
{
    sbr_get_fd_share(sk)->err = err;
    if (err != 0)
    {
        if (sbr_get_conn(sk))
        {
            NSSBR_LOGDBG("fd=%d,errno=%d,conn=%p,private_data=%p", sk->fd,
                         err, sbr_get_conn(sk),
                         ss_get_private_data(sbr_get_conn(sk)));
        }

        sbr_set_errno(err);
    }
}

/*****************************************************************************
*   Prototype    : sbr_get_sk_errno
*   Description  : get sk's errno
*   Input        : sbr_socket_t * sk
*   Output       : None
*   Return Value : static inline int
*   Calls        :
*   Called By    :
*
*****************************************************************************/
static inline int sbr_get_sk_errno(sbr_socket_t * sk)
{
    return sbr_get_fd_share(sk)->err;
}

#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif

#endif