1/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 *     Copyright 2019 Couchbase, Inc.
4 *
5 *   Licensed under the Apache License, Version 2.0 (the "License");
6 *   you may not use this file except in compliance with the License.
7 *   You may obtain a copy of the License at
8 *
9 *       http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *   Unless required by applicable law or agreed to in writing, software
12 *   distributed under the License is distributed on an "AS IS" BASIS,
13 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *   See the License for the specific language governing permissions and
15 *   limitations under the License.
16 */
17
18/*
19 * Header including C socket portability declarations
20 */
21#pragma once
22
23#include <platform/dynamic.h>
24#include <platform/visibility.h>
25
26#include <stdint.h>
27
28#ifdef WIN32
29#include <winsock2.h>
30#endif
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36#ifdef WIN32
37#define CB_DONT_NEED_BYTEORDER 1
38struct iovec {
39    size_t iov_len;
40    void* iov_base;
41};
42
43#define IOV_MAX 1024
44
45struct msghdr {
46    void* msg_name; /* Socket name */
47    int msg_namelen; /* Length of name */
48    struct iovec* msg_iov; /* Data blocks */
49    int msg_iovlen; /* Number of blocks */
50};
51
52PLATFORM_PUBLIC_API
53int sendmsg(SOCKET sock, const struct msghdr* msg, int flags);
54
55/**
56 * Initialize the winsock library
57 */
58PLATFORM_PUBLIC_API
59void cb_initialize_sockets(void);
60#else // WIN32
61#define cb_initialize_sockets()
62#endif // WIN32
63
64#ifndef CB_DONT_NEED_BYTEORDER
65PLATFORM_PUBLIC_API
66uint64_t ntohll(uint64_t);
67
68PLATFORM_PUBLIC_API
69uint64_t htonll(uint64_t);
70#endif
71
72#ifdef __cplusplus
73}
74#endif
75