xref: /third_party/libcoap/include/coap3/coap_io.h (revision c87c5fba)
1c87c5fbaSopenharmony_ci/*
2c87c5fbaSopenharmony_ci * coap_io.h -- Default network I/O functions for libcoap
3c87c5fbaSopenharmony_ci *
4c87c5fbaSopenharmony_ci * Copyright (C) 2012-2013,2023 Olaf Bergmann <bergmann@tzi.org>
5c87c5fbaSopenharmony_ci *
6c87c5fbaSopenharmony_ci * SPDX-License-Identifier: BSD-2-Clause
7c87c5fbaSopenharmony_ci *
8c87c5fbaSopenharmony_ci * This file is part of the CoAP library libcoap. Please see README for terms
9c87c5fbaSopenharmony_ci * of use.
10c87c5fbaSopenharmony_ci */
11c87c5fbaSopenharmony_ci
12c87c5fbaSopenharmony_ci/**
13c87c5fbaSopenharmony_ci * @file coap_io.h
14c87c5fbaSopenharmony_ci * @brief Default network I/O functions
15c87c5fbaSopenharmony_ci */
16c87c5fbaSopenharmony_ci
17c87c5fbaSopenharmony_ci#ifndef COAP_IO_H_
18c87c5fbaSopenharmony_ci#define COAP_IO_H_
19c87c5fbaSopenharmony_ci
20c87c5fbaSopenharmony_ci#include <sys/types.h>
21c87c5fbaSopenharmony_ci
22c87c5fbaSopenharmony_ci#include "coap_address.h"
23c87c5fbaSopenharmony_ci
24c87c5fbaSopenharmony_ci#ifdef RIOT_VERSION
25c87c5fbaSopenharmony_ci#include "net/gnrc.h"
26c87c5fbaSopenharmony_ci#endif /* RIOT_VERSION */
27c87c5fbaSopenharmony_ci
28c87c5fbaSopenharmony_ci#ifndef COAP_RXBUFFER_SIZE
29c87c5fbaSopenharmony_ci#define COAP_RXBUFFER_SIZE 1472
30c87c5fbaSopenharmony_ci#endif /* COAP_RXBUFFER_SIZE */
31c87c5fbaSopenharmony_ci
32c87c5fbaSopenharmony_ci/*
33c87c5fbaSopenharmony_ci * It may may make sense to define this larger on busy systems
34c87c5fbaSopenharmony_ci * (lots of sessions, large number of which are active), by using
35c87c5fbaSopenharmony_ci * -DCOAP_MAX_EPOLL_EVENTS=nn at compile time.
36c87c5fbaSopenharmony_ci */
37c87c5fbaSopenharmony_ci#ifndef COAP_MAX_EPOLL_EVENTS
38c87c5fbaSopenharmony_ci#define COAP_MAX_EPOLL_EVENTS 10
39c87c5fbaSopenharmony_ci#endif /* COAP_MAX_EPOLL_EVENTS */
40c87c5fbaSopenharmony_ci
41c87c5fbaSopenharmony_ci#ifdef _WIN32
42c87c5fbaSopenharmony_citypedef SOCKET coap_fd_t;
43c87c5fbaSopenharmony_ci#define coap_closesocket closesocket
44c87c5fbaSopenharmony_ci#define COAP_SOCKET_ERROR SOCKET_ERROR
45c87c5fbaSopenharmony_ci#define COAP_INVALID_SOCKET INVALID_SOCKET
46c87c5fbaSopenharmony_ci#else
47c87c5fbaSopenharmony_citypedef int coap_fd_t;
48c87c5fbaSopenharmony_ci#define coap_closesocket close
49c87c5fbaSopenharmony_ci#define COAP_SOCKET_ERROR (-1)
50c87c5fbaSopenharmony_ci#define COAP_INVALID_SOCKET (-1)
51c87c5fbaSopenharmony_ci#endif
52c87c5fbaSopenharmony_ci
53c87c5fbaSopenharmony_citypedef uint16_t coap_socket_flags_t;
54c87c5fbaSopenharmony_ci
55c87c5fbaSopenharmony_citypedef struct coap_addr_tuple_t {
56c87c5fbaSopenharmony_ci  coap_address_t remote;       /**< remote address and port */
57c87c5fbaSopenharmony_ci  coap_address_t local;        /**< local address and port */
58c87c5fbaSopenharmony_ci} coap_addr_tuple_t;
59c87c5fbaSopenharmony_ci
60c87c5fbaSopenharmony_ciconst char *coap_socket_strerror(void);
61c87c5fbaSopenharmony_ci
62c87c5fbaSopenharmony_ci/**
63c87c5fbaSopenharmony_ci * Check whether TCP is available.
64c87c5fbaSopenharmony_ci *
65c87c5fbaSopenharmony_ci * @return @c 1 if support for TCP is enabled, or @c 0 otherwise.
66c87c5fbaSopenharmony_ci */
67c87c5fbaSopenharmony_ciint coap_tcp_is_supported(void);
68c87c5fbaSopenharmony_ci
69c87c5fbaSopenharmony_citypedef enum {
70c87c5fbaSopenharmony_ci  COAP_NACK_TOO_MANY_RETRIES,
71c87c5fbaSopenharmony_ci  COAP_NACK_NOT_DELIVERABLE,
72c87c5fbaSopenharmony_ci  COAP_NACK_RST,
73c87c5fbaSopenharmony_ci  COAP_NACK_TLS_FAILED,
74c87c5fbaSopenharmony_ci  COAP_NACK_ICMP_ISSUE,
75c87c5fbaSopenharmony_ci  COAP_NACK_BAD_RESPONSE,
76c87c5fbaSopenharmony_ci  COAP_NACK_TLS_LAYER_FAILED,
77c87c5fbaSopenharmony_ci  COAP_NACK_WS_LAYER_FAILED,
78c87c5fbaSopenharmony_ci  COAP_NACK_WS_FAILED
79c87c5fbaSopenharmony_ci} coap_nack_reason_t;
80c87c5fbaSopenharmony_ci
81c87c5fbaSopenharmony_ci#endif /* COAP_IO_H_ */
82