Instrument Neutral Distributed Interface INDI 2.2.5
tcpsocket_win.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2022 by Pawel Soja <[email protected]>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17*/
18#include "tcpsocket.h"
19#include "tcpsocket_p.h"
20
21#ifdef _MSC_VER
22#pragma comment(lib, "Ws2_32.lib")
23#endif
24
25bool TcpSocketPrivate::createSocket(int domain)
26{
27 WSADATA wsaData;
28
29 if (WSAStartup(MAKEWORD(2, 2), &wsaData) != NO_ERROR)
30 {
31 return false;
32 }
33
34 socketFd = socket(domain, SOCK_STREAM, IPPROTO_TCP);
36 {
37 WSACleanup();
38 //IDLog("Socket error: %d\n", WSAGetLastError());
39 return false;
40 }
41 return true;
42}
43
45{
46 u_long iMode = 0;
47 int iResult = ioctlsocket(socketFd, FIONBIO, &iMode);
48 return iResult == NO_ERROR;
49}
50
51ssize_t TcpSocketPrivate::recvSocket(void *dst, size_t size)
52{
53 return ::recv(socketFd, static_cast<char *>(dst), int(size), 0);
54}
55
56ssize_t TcpSocketPrivate::sendSocket(const void *src, size_t size)
57{
58 return ::send(socketFd, static_cast<const char *>(src), int(size), 0);
59}
60
61SocketAddress SocketAddress::afUnix(const std::string &)
62{
63 return SocketAddress();
64}
SocketAddress()=default
static SocketAddress afUnix(const std::string &hostName)
bool createSocket(int domain)
SocketFileDescriptor socketFd
ssize_t sendSocket(const void *src, size_t size)
ssize_t recvSocket(void *dst, size_t size)
#define INVALID_SOCKET
Definition httplib.h:273