Skip to content

Commit c38d6f1

Browse files
xiaoxiang781216masayuki2009
authored andcommitted
net: Remove usrsock specific process from common code as much as possible
Signed-off-by: Xiang Xiao <[email protected]>
1 parent 699e3e8 commit c38d6f1

14 files changed

+71
-95
lines changed

net/socket/getsockopt.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include <errno.h>
3434

3535
#include "socket/socket.h"
36-
#include "usrsock/usrsock.h"
3736
#include "utils/utils.h"
3837

3938
/****************************************************************************
@@ -122,21 +121,11 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option,
122121

123122
/* Then return the timeout value to the caller */
124123

125-
net_dsec2timeval(timeo, (struct timeval *)value);
126-
*value_len = sizeof(struct timeval);
124+
net_dsec2timeval(timeo, (FAR struct timeval *)value);
125+
*value_len = sizeof(struct timeval);
127126
return OK;
128127
}
129-
}
130128

131-
#ifdef CONFIG_NET_USRSOCK
132-
if (psock->s_type == SOCK_USRSOCK_TYPE)
133-
{
134-
return -ENOPROTOOPT;
135-
}
136-
#endif
137-
138-
switch (option)
139-
{
140129
case SO_ACCEPTCONN: /* Reports whether socket listening is enabled */
141130
{
142131
if (*value_len < sizeof(int))
@@ -297,6 +286,13 @@ int psock_getsockopt(FAR struct socket *psock, int level, int option,
297286
ret = psock_socketlevel_option(psock, option, value, value_len);
298287
}
299288

289+
/* -ENOTTY really mean -ENOPROTOOPT, but skip the default action */
290+
291+
else if (ret == -ENOTTY)
292+
{
293+
ret = -ENOPROTOOPT;
294+
}
295+
300296
return ret;
301297
}
302298

net/socket/net_sockif.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "pkt/pkt.h"
3939
#include "bluetooth/bluetooth.h"
4040
#include "ieee802154/ieee802154.h"
41+
#include "usrsock/usrsock.h"
4142
#include "socket/socket.h"
4243

4344
/****************************************************************************
@@ -75,12 +76,12 @@ net_sockif(sa_family_t family, int type, int protocol)
7576
switch (family)
7677
{
7778
#ifdef HAVE_INET_SOCKETS
78-
#ifdef HAVE_PFINET_SOCKETS
79+
# ifdef HAVE_PFINET_SOCKETS
7980
case PF_INET:
80-
#endif
81-
#ifdef HAVE_PFINET6_SOCKETS
81+
# endif
82+
# ifdef HAVE_PFINET6_SOCKETS
8283
case PF_INET6:
83-
#endif
84+
# endif
8485
sockif = inet_sockif(family, type, protocol);
8586
break;
8687
#endif
@@ -131,5 +132,12 @@ net_sockif(sa_family_t family, int type, int protocol)
131132
nerr("ERROR: Address family unsupported: %d\n", family);
132133
}
133134

135+
#ifdef CONFIG_NET_USRSOCK
136+
if (sockif == NULL)
137+
{
138+
sockif = &g_usrsock_sockif;
139+
}
140+
#endif
141+
134142
return sockif;
135143
}

net/socket/setsockopt.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#include <netdev/netdev.h>
3939

4040
#include "socket/socket.h"
41-
#include "usrsock/usrsock.h"
4241
#include "utils/utils.h"
4342

4443
/****************************************************************************
@@ -134,17 +133,7 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option,
134133

135134
return OK;
136135
}
137-
}
138-
139-
#ifdef CONFIG_NET_USRSOCK
140-
if (psock->s_type == SOCK_USRSOCK_TYPE)
141-
{
142-
return -ENOPROTOOPT;
143-
}
144-
#endif
145136

146-
switch (option)
147-
{
148137
case SO_BROADCAST: /* Permits sending of broadcast messages */
149138
case SO_DEBUG: /* Enables recording of debugging information */
150139
case SO_DONTROUTE: /* Requests outgoing messages bypass standard routing */
@@ -329,6 +318,13 @@ int psock_setsockopt(FAR struct socket *psock, int level, int option,
329318
ret = psock_socketlevel_option(psock, option, value, value_len);
330319
}
331320

321+
/* -ENOTTY really mean -ENOPROTOOPT, but skip the default action */
322+
323+
else if (ret == -ENOTTY)
324+
{
325+
ret = -ENOPROTOOPT;
326+
}
327+
332328
return ret;
333329
}
334330

net/socket/socket.c

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include <assert.h>
3030
#include <debug.h>
3131

32-
#include "usrsock/usrsock.h"
3332
#include "socket/socket.h"
3433

3534
#ifdef CONFIG_NET
@@ -94,38 +93,23 @@ int psock_socket(int domain, int type, int protocol,
9493
psock->s_conn = NULL;
9594
psock->s_type = type & SOCK_TYPE_MASK;
9695

97-
#ifdef CONFIG_NET_USRSOCK
98-
if (domain != PF_LOCAL && domain != PF_UNSPEC && domain != PF_RPMSG)
99-
{
100-
/* Handle special setup for USRSOCK sockets (user-space networking
101-
* stack).
102-
*/
96+
/* Get the socket interface */
10397

104-
ret = g_usrsock_sockif.si_setup(psock, protocol);
105-
psock->s_sockif = &g_usrsock_sockif;
106-
}
107-
else
108-
#endif /* CONFIG_NET_USRSOCK */
98+
sockif = net_sockif(domain, psock->s_type, protocol);
99+
if (sockif == NULL)
109100
{
110-
/* Get the socket interface */
111-
112-
sockif = net_sockif(domain, psock->s_type, protocol);
113-
if (sockif == NULL)
114-
{
115-
nerr("ERROR: socket address family unsupported: %d\n", domain);
116-
return -EAFNOSUPPORT;
117-
}
118-
119-
/* The remaining of the socket initialization depends on the address
120-
* family.
121-
*/
101+
nerr("ERROR: socket address family unsupported: %d\n", domain);
102+
return -EAFNOSUPPORT;
103+
}
122104

123-
DEBUGASSERT(sockif->si_setup != NULL);
124-
psock->s_sockif = sockif;
105+
/* The remaining of the socket initialization depends on the address
106+
* family.
107+
*/
125108

126-
ret = sockif->si_setup(psock, protocol);
127-
}
109+
DEBUGASSERT(sockif->si_setup != NULL);
110+
psock->s_sockif = sockif;
128111

112+
ret = sockif->si_setup(psock, protocol);
129113
if (ret >= 0)
130114
{
131115
FAR struct socket_conn_s *conn = psock->s_conn;

net/usrsock/usrsock.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@
4141
* Pre-processor Definitions
4242
****************************************************************************/
4343

44-
/* Internal socket type/domain for marking usrsock sockets */
45-
46-
#define SOCK_USRSOCK_TYPE 0x7f
47-
#define PF_USRSOCK_DOMAIN 0x7f
48-
4944
/* Internal event flags */
5045

5146
#define USRSOCK_EVENT_CONNECT_READY (1 << 0)
@@ -84,7 +79,6 @@ struct usrsock_conn_s
8479

8580
enum usrsock_conn_state_e state; /* State of kernel<->daemon link for conn */
8681
bool connected; /* Socket has been connected */
87-
int8_t type; /* Socket type (SOCK_STREAM, etc) */
8882
int16_t usockid; /* Connection number used for kernel<->daemon */
8983
uint16_t flags; /* Socket state flags */
9084

net/usrsock/usrsock_accept.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@ int usrsock_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
409409
if (ret >= 0)
410410
{
411411
newconn->connected = true;
412-
newconn->type = conn->type;
413412
newconn->crefs = 1;
414413

415414
newsock->s_type = psock->s_type;

net/usrsock/usrsock_connect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ int usrsock_connect(FAR struct socket *psock,
172172
}
173173

174174
if (conn->connected &&
175-
(conn->type == SOCK_STREAM || conn->type == SOCK_SEQPACKET))
175+
(psock->s_type == SOCK_STREAM || psock->s_type == SOCK_SEQPACKET))
176176
{
177177
/* Already connected. */
178178

net/usrsock/usrsock_getsockopt.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -179,20 +179,12 @@ int usrsock_getsockopt(FAR struct socket *psock, int level, int option,
179179
struct iovec inbufs[1];
180180
int ret;
181181

182-
if (level == SOL_SOCKET)
183-
{
184-
if (option == SO_TYPE)
185-
{
186-
/* Return the actual socket type */
182+
/* SO_[RCV|SND]TIMEO have to be handled locally to break the block i/o */
187183

188-
*(FAR int *)value = conn->type;
189-
*value_len = sizeof(int);
190-
return OK;
191-
}
192-
else if (option == SO_RCVTIMEO || option == SO_SNDTIMEO)
193-
{
194-
return -ENOPROTOOPT;
195-
}
184+
if (level == SOL_SOCKET && (option == SO_TYPE ||
185+
option == SO_RCVTIMEO || option == SO_SNDTIMEO))
186+
{
187+
return -ENOPROTOOPT;
196188
}
197189

198190
net_lock();
@@ -249,6 +241,13 @@ int usrsock_getsockopt(FAR struct socket *psock, int level, int option,
249241
usrsock_teardown_datain(conn);
250242
usrsock_teardown_data_request_callback(&state);
251243

244+
/* Skip the default socket option handler */
245+
246+
if (ret == -ENOPROTOOPT)
247+
{
248+
ret = -ENOTTY;
249+
}
250+
252251
errout_unlock:
253252
net_unlock();
254253
return ret;

net/usrsock/usrsock_poll.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ static int usrsock_pollsetup(FAR struct socket *psock,
200200

201201
/* Stream sockets need to be connected or connecting (or listening). */
202202

203-
else if ((conn->type == SOCK_STREAM ||
204-
conn->type == SOCK_SEQPACKET) &&
203+
else if ((psock->s_type == SOCK_STREAM ||
204+
psock->s_type == SOCK_SEQPACKET) &&
205205
!(conn->connected || conn->state ==
206206
USRSOCK_CONN_STATE_CONNECTING))
207207
{

net/usrsock/usrsock_recvmsg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ ssize_t usrsock_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
246246
goto errout_unlock;
247247
}
248248

249-
if (conn->type == SOCK_STREAM || conn->type == SOCK_SEQPACKET)
249+
if (psock->s_type == SOCK_STREAM || psock->s_type == SOCK_SEQPACKET)
250250
{
251251
if (!conn->connected)
252252
{

net/usrsock/usrsock_sendmsg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ ssize_t usrsock_sendmsg(FAR struct socket *psock,
225225
goto errout_unlock;
226226
}
227227

228-
if (conn->type == SOCK_STREAM || conn->type == SOCK_SEQPACKET)
228+
if (psock->s_type == SOCK_STREAM || psock->s_type == SOCK_SEQPACKET)
229229
{
230230
if (!conn->connected)
231231
{

net/usrsock/usrsock_setsockopt.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,13 @@ int usrsock_setsockopt(FAR struct socket *psock, int level, int option,
168168
int ret;
169169

170170
DEBUGASSERT(conn);
171-
if (level == SOL_SOCKET)
171+
172+
/* SO_[RCV|SND]TIMEO have to be handled locally to break the block i/o */
173+
174+
if (level == SOL_SOCKET && (option == SO_TYPE ||
175+
option == SO_RCVTIMEO || option == SO_SNDTIMEO))
172176
{
173-
if (option == SO_RCVTIMEO || option == SO_SNDTIMEO)
174-
{
175-
return -ENOPROTOOPT;
176-
}
177+
return -ENOPROTOOPT;
177178
}
178179

179180
net_lock();
@@ -215,6 +216,13 @@ int usrsock_setsockopt(FAR struct socket *psock, int level, int option,
215216

216217
usrsock_teardown_request_callback(&state);
217218

219+
/* Skip the default socket option handler */
220+
221+
if (ret == -ENOPROTOOPT)
222+
{
223+
ret = -ENOTTY;
224+
}
225+
218226
errout_unlock:
219227
net_unlock();
220228
return ret;

net/usrsock/usrsock_socket.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,6 @@ int usrsock_socket(int domain, int type, int protocol,
233233
goto errout_teardown_callback;
234234
}
235235

236-
psock->s_type = SOCK_USRSOCK_TYPE;
237-
psock->s_domain = PF_USRSOCK_DOMAIN;
238-
conn->type = type;
239236
psock->s_conn = conn;
240237
conn->crefs = 1;
241238

net/usrsock/usrsock_sockif.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,8 @@ const struct sock_intf_s g_usrsock_sockif =
9999

100100
static int usrsock_sockif_setup(FAR struct socket *psock, int protocol)
101101
{
102-
int domain = psock->s_domain;
103-
int type = psock->s_type;
104102
int ret;
105103

106-
psock->s_type = PF_UNSPEC;
107-
psock->s_conn = NULL;
108-
109104
/* Let the user socket logic handle the setup...
110105
*
111106
* A return value of zero means that the operation was
@@ -115,7 +110,7 @@ static int usrsock_sockif_setup(FAR struct socket *psock, int protocol)
115110
* to open socket with kernel networking stack in this case.
116111
*/
117112

118-
ret = usrsock_socket(domain, type, protocol, psock);
113+
ret = usrsock_socket(psock->s_domain, psock->s_type, protocol, psock);
119114
if (ret == -ENETDOWN)
120115
{
121116
nwarn("WARNING: usrsock daemon is not running\n");

0 commit comments

Comments
 (0)