Skip to content

Commit 7eaf32b

Browse files
authored
Merge pull request #3075 from geky/nsapi-error-size-types-2
nsapi - Add standardized return types for size and errors
2 parents 03b8ae1 + 00458c3 commit 7eaf32b

File tree

24 files changed

+308
-259
lines changed

24 files changed

+308
-259
lines changed

features/FEATURE_LWIP/lwip-interface/EthernetInterface.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,30 @@ EthernetInterface::EthernetInterface()
2424
{
2525
}
2626

27-
int EthernetInterface::set_network(const char *ip_address, const char *netmask, const char *gateway)
27+
nsapi_error_t EthernetInterface::set_network(const char *ip_address, const char *netmask, const char *gateway)
2828
{
2929
_dhcp = false;
3030
strncpy(_ip_address, ip_address ? ip_address : "", sizeof(_ip_address));
3131
strncpy(_netmask, netmask ? netmask : "", sizeof(_netmask));
3232
strncpy(_gateway, gateway ? gateway : "", sizeof(_gateway));
33-
return 0;
33+
return NSAPI_ERROR_OK;
3434
}
3535

36-
int EthernetInterface::set_dhcp(bool dhcp)
36+
nsapi_error_t EthernetInterface::set_dhcp(bool dhcp)
3737
{
3838
_dhcp = dhcp;
39-
return 0;
39+
return NSAPI_ERROR_OK;
4040
}
4141

42-
int EthernetInterface::connect()
42+
nsapi_error_t EthernetInterface::connect()
4343
{
4444
return mbed_lwip_bringup(_dhcp,
4545
_ip_address[0] ? _ip_address : 0,
4646
_netmask[0] ? _netmask : 0,
4747
_gateway[0] ? _gateway : 0);
4848
}
4949

50-
int EthernetInterface::disconnect()
50+
nsapi_error_t EthernetInterface::disconnect()
5151
{
5252
return mbed_lwip_bringdown();
5353
}
@@ -63,7 +63,7 @@ const char *EthernetInterface::get_ip_address()
6363
return _ip_address;
6464
}
6565

66-
return 0;
66+
return NULL;
6767
}
6868

6969
const char *EthernetInterface::get_netmask()

features/FEATURE_LWIP/lwip-interface/EthernetInterface.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ class EthernetInterface : public EthInterface
4646
* @param gateway Null-terminated representation of the local gateway
4747
* @return 0 on success, negative error code on failure
4848
*/
49-
virtual int set_network(const char *ip_address, const char *netmask, const char *gateway);
49+
virtual nsapi_error_t set_network(
50+
const char *ip_address, const char *netmask, const char *gateway);
5051

5152
/** Enable or disable DHCP on the network
5253
*
@@ -55,17 +56,17 @@ class EthernetInterface : public EthInterface
5556
* @param dhcp False to disable dhcp (defaults to enabled)
5657
* @return 0 on success, negative error code on failure
5758
*/
58-
virtual int set_dhcp(bool dhcp);
59+
virtual nsapi_error_t set_dhcp(bool dhcp);
5960

6061
/** Start the interface
6162
* @return 0 on success, negative on failure
6263
*/
63-
virtual int connect();
64+
virtual nsapi_error_t connect();
6465

6566
/** Stop the interface
6667
* @return 0 on success, negative on failure
6768
*/
68-
virtual int disconnect();
69+
virtual nsapi_error_t disconnect();
6970

7071
/** Get the local MAC address
7172
*

features/FEATURE_LWIP/lwip-interface/lwip_stack.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ const char *mbed_lwip_get_mac_address(void)
326326
return lwip_mac_address[0] ? lwip_mac_address : 0;
327327
}
328328

329-
char *mbed_lwip_get_ip_address(char *buf, int buflen)
329+
char *mbed_lwip_get_ip_address(char *buf, nsapi_size_t buflen)
330330
{
331331
const ip_addr_t *addr = mbed_lwip_get_ip_addr(true, &lwip_netif);
332332
if (!addr) {
@@ -345,7 +345,7 @@ char *mbed_lwip_get_ip_address(char *buf, int buflen)
345345
return NULL;
346346
}
347347

348-
const char *mbed_lwip_get_netmask(char *buf, int buflen)
348+
const char *mbed_lwip_get_netmask(char *buf, nsapi_size_t buflen)
349349
{
350350
#if LWIP_IPV4
351351
const ip4_addr_t *addr = netif_ip4_netmask(&lwip_netif);
@@ -359,7 +359,7 @@ const char *mbed_lwip_get_netmask(char *buf, int buflen)
359359
#endif
360360
}
361361

362-
char *mbed_lwip_get_gateway(char *buf, int buflen)
362+
char *mbed_lwip_get_gateway(char *buf, nsapi_size_t buflen)
363363
{
364364
#if LWIP_IPV4
365365
const ip4_addr_t *addr = netif_ip4_gw(&lwip_netif);
@@ -373,7 +373,7 @@ char *mbed_lwip_get_gateway(char *buf, int buflen)
373373
#endif
374374
}
375375

376-
int mbed_lwip_init(emac_interface_t *emac)
376+
nsapi_error_t mbed_lwip_init(emac_interface_t *emac)
377377
{
378378
// Check if we've already brought up lwip
379379
if (!mbed_lwip_get_mac_address()) {
@@ -409,7 +409,7 @@ int mbed_lwip_init(emac_interface_t *emac)
409409
return NSAPI_ERROR_OK;
410410
}
411411

412-
int mbed_lwip_bringup(bool dhcp, const char *ip, const char *netmask, const char *gw)
412+
nsapi_error_t mbed_lwip_bringup(bool dhcp, const char *ip, const char *netmask, const char *gw)
413413
{
414414
// Check if we've already connected
415415
if (lwip_connected) {
@@ -509,7 +509,7 @@ int mbed_lwip_bringup(bool dhcp, const char *ip, const char *netmask, const char
509509
return 0;
510510
}
511511

512-
int mbed_lwip_bringdown(void)
512+
nsapi_error_t mbed_lwip_bringdown(void)
513513
{
514514
// Check if we've connected
515515
if (!lwip_connected) {
@@ -533,7 +533,7 @@ int mbed_lwip_bringdown(void)
533533
}
534534

535535
/* LWIP error remapping */
536-
static int mbed_lwip_err_remap(err_t err) {
536+
static nsapi_error_t mbed_lwip_err_remap(err_t err) {
537537
switch (err) {
538538
case ERR_OK:
539539
case ERR_CLSD:
@@ -559,7 +559,7 @@ static int mbed_lwip_err_remap(err_t err) {
559559
}
560560

561561
/* LWIP network stack implementation */
562-
static int mbed_lwip_gethostbyname(nsapi_stack_t *stack, const char *host, nsapi_addr_t *addr, nsapi_version_t version)
562+
static nsapi_error_t mbed_lwip_gethostbyname(nsapi_stack_t *stack, const char *host, nsapi_addr_t *addr, nsapi_version_t version)
563563
{
564564
ip_addr_t lwip_addr;
565565

@@ -600,7 +600,7 @@ static int mbed_lwip_gethostbyname(nsapi_stack_t *stack, const char *host, nsapi
600600
return 0;
601601
}
602602

603-
static int mbed_lwip_socket_open(nsapi_stack_t *stack, nsapi_socket_t *handle, nsapi_protocol_t proto)
603+
static nsapi_error_t mbed_lwip_socket_open(nsapi_stack_t *stack, nsapi_socket_t *handle, nsapi_protocol_t proto)
604604
{
605605
// check if network is connected
606606
if (!lwip_connected) {
@@ -643,7 +643,7 @@ static int mbed_lwip_socket_open(nsapi_stack_t *stack, nsapi_socket_t *handle, n
643643
return 0;
644644
}
645645

646-
static int mbed_lwip_socket_close(nsapi_stack_t *stack, nsapi_socket_t handle)
646+
static nsapi_error_t mbed_lwip_socket_close(nsapi_stack_t *stack, nsapi_socket_t handle)
647647
{
648648
struct lwip_socket *s = (struct lwip_socket *)handle;
649649

@@ -652,7 +652,7 @@ static int mbed_lwip_socket_close(nsapi_stack_t *stack, nsapi_socket_t handle)
652652
return mbed_lwip_err_remap(err);
653653
}
654654

655-
static int mbed_lwip_socket_bind(nsapi_stack_t *stack, nsapi_socket_t handle, nsapi_addr_t addr, uint16_t port)
655+
static nsapi_error_t mbed_lwip_socket_bind(nsapi_stack_t *stack, nsapi_socket_t handle, nsapi_addr_t addr, uint16_t port)
656656
{
657657
struct lwip_socket *s = (struct lwip_socket *)handle;
658658
ip_addr_t ip_addr;
@@ -670,15 +670,15 @@ static int mbed_lwip_socket_bind(nsapi_stack_t *stack, nsapi_socket_t handle, ns
670670
return mbed_lwip_err_remap(err);
671671
}
672672

673-
static int mbed_lwip_socket_listen(nsapi_stack_t *stack, nsapi_socket_t handle, int backlog)
673+
static nsapi_error_t mbed_lwip_socket_listen(nsapi_stack_t *stack, nsapi_socket_t handle, int backlog)
674674
{
675675
struct lwip_socket *s = (struct lwip_socket *)handle;
676676

677677
err_t err = netconn_listen_with_backlog(s->conn, backlog);
678678
return mbed_lwip_err_remap(err);
679679
}
680680

681-
static int mbed_lwip_socket_connect(nsapi_stack_t *stack, nsapi_socket_t handle, nsapi_addr_t addr, uint16_t port)
681+
static nsapi_error_t mbed_lwip_socket_connect(nsapi_stack_t *stack, nsapi_socket_t handle, nsapi_addr_t addr, uint16_t port)
682682
{
683683
struct lwip_socket *s = (struct lwip_socket *)handle;
684684
ip_addr_t ip_addr;
@@ -694,7 +694,7 @@ static int mbed_lwip_socket_connect(nsapi_stack_t *stack, nsapi_socket_t handle,
694694
return mbed_lwip_err_remap(err);
695695
}
696696

697-
static int mbed_lwip_socket_accept(nsapi_stack_t *stack, nsapi_socket_t server, nsapi_socket_t *handle, nsapi_addr_t *addr, uint16_t *port)
697+
static nsapi_error_t mbed_lwip_socket_accept(nsapi_stack_t *stack, nsapi_socket_t server, nsapi_socket_t *handle, nsapi_addr_t *addr, uint16_t *port)
698698
{
699699
struct lwip_socket *s = (struct lwip_socket *)server;
700700
struct lwip_socket *ns = mbed_lwip_arena_alloc();
@@ -718,7 +718,7 @@ static int mbed_lwip_socket_accept(nsapi_stack_t *stack, nsapi_socket_t server,
718718
return 0;
719719
}
720720

721-
static int mbed_lwip_socket_send(nsapi_stack_t *stack, nsapi_socket_t handle, const void *data, unsigned size)
721+
static nsapi_size_or_error_t mbed_lwip_socket_send(nsapi_stack_t *stack, nsapi_socket_t handle, const void *data, nsapi_size_t size)
722722
{
723723
struct lwip_socket *s = (struct lwip_socket *)handle;
724724
size_t bytes_written = 0;
@@ -728,10 +728,10 @@ static int mbed_lwip_socket_send(nsapi_stack_t *stack, nsapi_socket_t handle, co
728728
return mbed_lwip_err_remap(err);
729729
}
730730

731-
return (int)bytes_written;
731+
return (nsapi_size_or_error_t)bytes_written;
732732
}
733733

734-
static int mbed_lwip_socket_recv(nsapi_stack_t *stack, nsapi_socket_t handle, void *data, unsigned size)
734+
static nsapi_size_or_error_t mbed_lwip_socket_recv(nsapi_stack_t *stack, nsapi_socket_t handle, void *data, nsapi_size_t size)
735735
{
736736
struct lwip_socket *s = (struct lwip_socket *)handle;
737737

@@ -755,7 +755,7 @@ static int mbed_lwip_socket_recv(nsapi_stack_t *stack, nsapi_socket_t handle, vo
755755
return recv;
756756
}
757757

758-
static int mbed_lwip_socket_sendto(nsapi_stack_t *stack, nsapi_socket_t handle, nsapi_addr_t addr, uint16_t port, const void *data, unsigned size)
758+
static nsapi_size_or_error_t mbed_lwip_socket_sendto(nsapi_stack_t *stack, nsapi_socket_t handle, nsapi_addr_t addr, uint16_t port, const void *data, nsapi_size_t size)
759759
{
760760
struct lwip_socket *s = (struct lwip_socket *)handle;
761761
ip_addr_t ip_addr;
@@ -780,7 +780,7 @@ static int mbed_lwip_socket_sendto(nsapi_stack_t *stack, nsapi_socket_t handle,
780780
return size;
781781
}
782782

783-
static int mbed_lwip_socket_recvfrom(nsapi_stack_t *stack, nsapi_socket_t handle, nsapi_addr_t *addr, uint16_t *port, void *data, unsigned size)
783+
static nsapi_size_or_error_t mbed_lwip_socket_recvfrom(nsapi_stack_t *stack, nsapi_socket_t handle, nsapi_addr_t *addr, uint16_t *port, void *data, nsapi_size_t size)
784784
{
785785
struct lwip_socket *s = (struct lwip_socket *)handle;
786786
struct netbuf *buf;
@@ -799,7 +799,7 @@ static int mbed_lwip_socket_recvfrom(nsapi_stack_t *stack, nsapi_socket_t handle
799799
return recv;
800800
}
801801

802-
static int mbed_lwip_setsockopt(nsapi_stack_t *stack, nsapi_socket_t handle, int level, int optname, const void *optval, unsigned optlen)
802+
static nsapi_error_t mbed_lwip_setsockopt(nsapi_stack_t *stack, nsapi_socket_t handle, int level, int optname, const void *optval, unsigned optlen)
803803
{
804804
struct lwip_socket *s = (struct lwip_socket *)handle;
805805

features/FEATURE_LWIP/lwip-interface/lwip_stack.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ extern "C" {
2525
#endif
2626

2727
// Access to lwip through the nsapi
28-
int mbed_lwip_init(emac_interface_t *emac);
29-
int mbed_lwip_bringup(bool dhcp, const char *ip, const char *netmask, const char *gw);
30-
int mbed_lwip_bringdown(void);
28+
nsapi_error_t mbed_lwip_init(emac_interface_t *emac);
29+
nsapi_error_t mbed_lwip_bringup(bool dhcp, const char *ip, const char *netmask, const char *gw);
30+
nsapi_error_t mbed_lwip_bringdown(void);
3131

3232
const char *mbed_lwip_get_mac_address(void);
3333
char *mbed_lwip_get_ip_address(char *buf, int buflen);

0 commit comments

Comments
 (0)