Skip to content

Commit 3fa1bb6

Browse files
committed
Revised stack specific configurations
Adds the following functions for direct configuration of interface - (set|get)stackopt - (set|get)sockopt
1 parent 63725d6 commit 3fa1bb6

File tree

4 files changed

+77
-40
lines changed

4 files changed

+77
-40
lines changed

NetworkInterface.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,23 @@ int NetworkInterface::gethostbyname(SocketAddress *address, const char *name)
2828
address->set_ip_address(buffer);
2929
return 0;
3030
}
31+
32+
int NetworkInterface::setstackopt(int level, int optname, const void *optval, unsigned optlen)
33+
{
34+
return NSAPI_ERROR_UNSUPPORTED;
35+
}
36+
37+
int NetworkInterface::getstackopt(int level, int optname, void *optval, unsigned *optlen)
38+
{
39+
return NSAPI_ERROR_UNSUPPORTED;
40+
}
41+
42+
int NetworkInterface::setsockopt(void *handle, int level, int optname, const void *optval, unsigned optlen)
43+
{
44+
return NSAPI_ERROR_UNSUPPORTED;
45+
}
46+
47+
int NetworkInterface::getsockopt(void *handle, int level, int optname, void *optval, unsigned *optlen)
48+
{
49+
return NSAPI_ERROR_UNSUPPORTED;
50+
}

NetworkInterface.h

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ enum nsapi_error_t {
3636
NSAPI_ERROR_AUTH_FAILURE = -3009, /*!< connection to access point faield */
3737
NSAPI_ERROR_DEVICE_ERROR = -3010, /*!< failure interfacing with the network procesor */
3838
};
39-
40-
/** Enum of available options
41-
* @enum nsapi_opt_t
42-
*/
43-
enum nsapi_opt_t {
44-
};
4539

4640
/** Enum of socket protocols
4741
* @enum protocol_t
@@ -93,6 +87,24 @@ class NetworkInterface
9387
*/
9488
virtual int gethostbyname(SocketAddress *address, const char *name);
9589

90+
/* Set stack options
91+
* @param level Option level
92+
* @param optname Option identifier
93+
* @param optval Option value
94+
* @param optlen Length of the option value
95+
* @return 0 on success, negative on failure
96+
*/
97+
virtual int setstackopt(int level, int optname, const void *optval, unsigned optlen);
98+
99+
/* Get stack options
100+
* @param level Option level
101+
* @param optname Option identifier
102+
* @param optval Buffer where to write option value
103+
* @param optlen Length of the option value
104+
* @return 0 on success, negative on failure
105+
*/
106+
virtual int getstackopt(int level, int optname, void *optval, unsigned *optlen);
107+
96108
protected:
97109
friend class Socket;
98110
friend class UDPSocket;
@@ -114,24 +126,6 @@ class NetworkInterface
114126
*/
115127
virtual int socket_close(void *handle) = 0;
116128

117-
/** Set socket options
118-
* @param handle Socket handle
119-
* @param optname Option ID
120-
* @param optval Option value
121-
* @param optlen Length of the option value
122-
* @return 0 on success, negative on failure
123-
*/
124-
virtual int socket_set_option(void *handle, int optname, const void *optval, unsigned int optlen) = 0;
125-
126-
/** Get socket options
127-
* @param handle Socket handle
128-
* @param optname Option ID
129-
* @param optval Buffer pointer where to write the option value
130-
* @param optlen Length of the option value
131-
* @return 0 on success, negative on failure
132-
*/
133-
virtual int socket_get_option(void *handle, int optname, void *optval, unsigned int *optlen) = 0;
134-
135129
/** Bind a server socket to a specific port
136130
* @param handle Socket handle
137131
* @param address Local address to listen for incoming connections on
@@ -220,6 +214,26 @@ class NetworkInterface
220214
* @note Callback may be called in an interrupt context.
221215
*/
222216
virtual void socket_attach(void *handle, void (*callback)(void *), void *data) = 0;
217+
218+
/* Set socket options
219+
* @param handle Socket handle
220+
* @param level Option level
221+
* @param optname Option identifier
222+
* @param optval Option value
223+
* @param optlen Length of the option value
224+
* @return 0 on success, negative on failure
225+
*/
226+
virtual int setsockopt(void *handle, int level, int optname, const void *optval, unsigned optlen);
227+
228+
/* Get socket options
229+
* @param handle Socket handle
230+
* @param level Option level
231+
* @param optname Option identifier
232+
* @param optval Buffer where to write option value
233+
* @param optlen Length of the option value
234+
* @return 0 on success, negative on failure
235+
*/
236+
virtual int getsockopt(void *handle, int level, int optname, void *optval, unsigned *optlen);
223237
};
224238

225239
#endif

Socket.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,23 @@ void Socket::set_timeout(unsigned timeout)
8989
_timeout = timeout;
9090
}
9191

92-
int Socket::set_option(int optname, const void *optval, unsigned int optlen)
92+
int Socket::setsockopt(int level, int optname, const void *optval, unsigned optlen)
9393
{
9494
if (!_socket) {
9595
return NSAPI_ERROR_NO_SOCKET;
9696
}
9797

98-
return _iface->socket_set_option(_socket, optname, optval, optlen);
98+
return _iface->setsockopt(_socket, level, optname, optval, optlen);
9999
}
100100

101-
int Socket::get_option(int optname, void *optval, unsigned int *optlen)
101+
int Socket::getsockopt(int level, int optname, void *optval, unsigned *optlen)
102102
{
103103
if (!_socket) {
104104
return NSAPI_ERROR_NO_SOCKET;
105105
}
106106

107-
return _iface->socket_get_option(_socket, optname, optval, optlen);
107+
return _iface->getsockopt(_socket, level, optname, optval, optlen);
108+
108109
}
109110

110111
void Socket::thunk(void *data)

Socket.h

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ class Socket {
3333
*/
3434
virtual int open(NetworkInterface *iface) = 0;
3535

36+
/** Close the socket
37+
*/
38+
int close();
39+
3640
/** Bind a socket to a specific port
3741
* @param port The port to listen for incoming connections on
3842
* @return 0 on success, negative on failure.
@@ -63,24 +67,22 @@ class Socket {
6367
void set_timeout(unsigned int timeout);
6468

6569
/* Set socket options
66-
* @param optname Option ID
70+
* @param level Option level
71+
* @param optname Option identifier
6772
* @param optval Option value
6873
* @param optlen Length of the option value
6974
* @return 0 on success, negative on failure
70-
*/
71-
int set_option(int optname, const void *optval, unsigned optlen);
72-
75+
*/
76+
int setsockopt(int level, int optname, const void *optval, unsigned optlen);
77+
7378
/* Get socket options
74-
* @param optname Option ID
75-
* @param optval Buffer pointer where to write the option value
79+
* @param level Option level
80+
* @param optname Option identifier
81+
* @param optval Buffer where to write option value
7682
* @param optlen Length of the option value
7783
* @return 0 on success, negative on failure
78-
*/
79-
int get_option(int optname, void *optval, unsigned *optlen);
80-
81-
/** Close the socket
82-
*/
83-
int close();
84+
*/
85+
int getsockopt(int level, int optname, void *optval, unsigned *optlen);
8486

8587
/** Register a callback on state change of the socket
8688
* @param callback Function to call on state change

0 commit comments

Comments
 (0)