/* coap_io_riot.c -- Default network I/O functions for libcoap on RIOT * * Copyright (C) 2019 Olaf Bergmann * * SPDX-License-Identifier: BSD-2-Clause * * This file is part of the CoAP library libcoap. Please see * README for terms of use. */ /** * @file coap_io_riot.c * @brief RIOT specific I/O functions */ #include "coap3/coap_internal.h" #ifdef HAVE_STDIO_H # include #endif #ifdef HAVE_SYS_SOCKET_H # include # define OPTVAL_T(t) (t) # define OPTVAL_GT(t) (t) #endif #ifdef HAVE_SYS_IOCTL_H #include #endif #ifdef HAVE_NETINET_IN_H # include #endif #ifdef HAVE_SYS_UIO_H # include #endif #ifdef HAVE_UNISTD_H # include #endif #include "net/gnrc.h" #include "net/gnrc/ipv6.h" #include "net/gnrc/netreg.h" #include "net/udp.h" #include "coap3/coap_riot.h" /* * dgram * return +ve Number of bytes written. * -1 Error error in errno). */ ssize_t coap_socket_send(coap_socket_t *sock, const coap_session_t *session, const uint8_t *data, size_t datalen) { ssize_t bytes_written = 0; if (!coap_debug_send_packet()) { bytes_written = (ssize_t)datalen; } else if (sock->flags & COAP_SOCKET_CONNECTED) { bytes_written = send(sock->fd, data, datalen, 0); } else { bytes_written = sendto(sock->fd, data, datalen, 0, &session->addr_info.remote.addr.sa, session->addr_info.remote.size); } if (bytes_written < 0) coap_log_crit("coap_socket_send: %s\n", coap_socket_strerror()); return bytes_written; } static msg_t _msg_q[LIBCOAP_MSG_QUEUE_SIZE]; void coap_riot_startup(void) { msg_init_queue(_msg_q, LIBCOAP_MSG_QUEUE_SIZE); }