/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
/* oslSocketAddr is a pointer to a Berkeley struct sockaddr. I refrained from using sockaddr_in because of possible further extensions of this socket-interface (IP-NG?). The intention was to hide all Berkeley data-structures from direct access past the osl-interface.
The current implementation is internet (IP) centered. All the constructor-functions (osl_create...) take parameters that will probably make sense only in the IP-environment (e.g. because of using the dotted-Addr-format).
If the interface will be extended to host other protocol- families, I expect no externally visible changes in the existing functions. You'll probably need only new constructor-functions who take the different Addr formats into consideration (maybe a long dotted Addr or whatever).
*/
/* _Note_ that I rely on the fact that oslSocketAddr and struct sockaddr are the same! I don't like it very much but see no other easy way to conceal the struct sockaddr from the eyes of the user.
*/
staticint SocketError[]= {
0, /* no error */
WSAENOTSOCK, /* Socket operation on non-socket */
WSAEDESTADDRREQ, /* Destination address required */
WSAEMSGSIZE, /* Message too long */
WSAEPROTOTYPE, /* Protocol wrong type for socket */
WSAENOPROTOOPT, /* Protocol not available */
WSAEPROTONOSUPPORT, /* Protocol not supported */
WSAESOCKTNOSUPPORT, /* Socket type not supported */
WSAEOPNOTSUPP, /* Operation not supported on socket */
WSAEPFNOSUPPORT, /* Protocol family not supported */
WSAEAFNOSUPPORT, /* Address family not supported by protocol family */
WSAEADDRINUSE, /* Address already in use */
WSAEADDRNOTAVAIL, /* Can't assign requested address */
WSAENETDOWN, /* Network is down */
WSAENETUNREACH, /* Network is unreachable */
WSAENETRESET, /* Network dropped connection because of reset */
WSAECONNABORTED, /* Software caused connection abort */
WSAECONNRESET, /* Connection reset by peer */
WSAENOBUFS, /* No buffer space available */
WSAEISCONN, /* Socket is already connected */
WSAENOTCONN, /* Socket is not connected */
WSAESHUTDOWN, /* Can't send after socket shutdown */
WSAETOOMANYREFS, /* Too many references: can't splice */
WSAETIMEDOUT, /* Connection timed out */
WSAECONNREFUSED, /* Connection refused */
WSAEHOSTDOWN, /* Host is down */
WSAEHOSTUNREACH, /* No route to host */
WSAEWOULDBLOCK, /* call would block on non-blocking socket */
WSAEALREADY, /* operation already in progress */
WSAEINPROGRESS /* operation now in progress */
};
/** Returns the addr field in the struct sockaddr. ppByteSeq is in network byteorder. *ppByteSeq may either be 0 or contain a constructed sal_Sequence.
*/
oslSocketResult SAL_CALL osl_getAddrOfSocketAddr( oslSocketAddr pAddr, sal_Sequence **ppByteSeq )
{
OSL_ASSERT( pAddr );
OSL_ASSERT( ppByteSeq );
/** Note that I rely on the fact that oslSocketAddr and struct sockaddr are the same! I don't like it very much but see no other easy way to conceal the struct sockaddr from the eyes of the user.
*/
oslSocketAddr SAL_CALL osl_getLocalAddrOfSocket(oslSocket pSocket)
{ struct sockaddr Addr; int AddrLen;
if (pSocket == nullptr) /* ENOTSOCK */ return nullptr;
AddrLen= sizeof(struct sockaddr);
if (getsockname(pSocket->m_Socket, &Addr, &AddrLen) == OSL_SOCKET_ERROR) return nullptr;
if (error > 0) /* connected */
{
SAL_WARN_IF(
!FD_ISSET(pSocket->m_Socket, &fds), "sal.osl", "osl_connectSocketTo(): select returned but socket not set");
Result= osl_Socket_Ok;
} elseif(error < 0) /* error */
{ /* errno == EBADF: most probably interrupted by close() */ if(WSAGetLastError() == WSAEBADF)
{ /* do not access pSockImpl because it is about to be or */ /* already destroyed */ return osl_Socket_Interrupted;
} else
Result= osl_Socket_Error;
} else/* timeout */
Result= osl_Socket_TimedOut;
/* clean up */
Param= 0;
ioctlsocket(pSocket->m_Socket, FIONBIO, &Param);
switch(error = WSAGetLastError())
{ case WSAENOTSOCK:
rtl_uString_newFromAscii (strError, "WSAENOTSOCK, Socket operation on non-socket. A socket created in one process is used by another process."); break;
case WSAEDESTADDRREQ:
rtl_uString_newFromAscii (strError, "WSAEDESTADDRREQ, Destination Addr required"); break;
case WSAEMSGSIZE:
rtl_uString_newFromAscii (strError, "WSAEMSGSIZE, Message too long"); break;
case WSAEPROTOTYPE:
rtl_uString_newFromAscii (strError, "WSAEPROTOTYPE, Protocol wrong type for socket"); break;
case WSAENOPROTOOPT:
rtl_uString_newFromAscii (strError, "WSAENOPROTOOPT, Protocol not available"); break;
case WSAEPROTONOSUPPORT:
rtl_uString_newFromAscii (strError, "WSAEPROTONOSUPPORT, Protocol not supported"); break;
case WSAESOCKTNOSUPPORT:
rtl_uString_newFromAscii (strError, "WSAESOCKTNOSUPPORT, Socket type not supported"); break;
case WSAEOPNOTSUPP:
rtl_uString_newFromAscii (strError, "WSAEOPNOTSUPP, Operation not supported on socket"); break;
case WSAEPFNOSUPPORT:
rtl_uString_newFromAscii (strError, "WSAEPFNOSUPPORT, Protocol family not supported"); break;
case WSAEAFNOSUPPORT:
rtl_uString_newFromAscii (strError, "WSEAFNOSUPPORT, Addr family not supported by protocol family"); break;
case WSAEADDRINUSE:
rtl_uString_newFromAscii (strError, "WSAEADDRINUSE, Triggered by bind() because a process went down without closing a socket."); break;
case WSAEADDRNOTAVAIL:
rtl_uString_newFromAscii (strError, "WSAEADDRNOTAVAIL, Can't assign requested Addr"); break;
case WSAENETDOWN:
rtl_uString_newFromAscii (strError, "WSAENETDOWN, Network is down"); break;
case WSAENETUNREACH:
rtl_uString_newFromAscii (strError, "WSAENETUNREACH, Network is unreachable"); break;
case WSAENETRESET:
rtl_uString_newFromAscii (strError, "WSAENETRESET, Network dropped connection or reset"); break;
case WSAECONNABORTED:
rtl_uString_newFromAscii (strError, "WSAECONNABORTED, Software caused connection abort"); break;
case WSAECONNRESET:
rtl_uString_newFromAscii (strError, "WSAECONNRESET, Connection reset by peer"); break;
case WSAENOBUFS:
rtl_uString_newFromAscii (strError, "WSAENOBUFS, No buffer space available."); break;
case WSAEISCONN:
rtl_uString_newFromAscii (strError, "WSAEISCONN, Socket is already connected"); break;
case WSAENOTCONN:
rtl_uString_newFromAscii (strError, "WSAENOTCONN, Socket is not connected"); break;
case WSAESHUTDOWN:
rtl_uString_newFromAscii (strError, "WSAESHUTDOWN, Can't send after socket shutdown"); break;
case WSAETIMEDOUT:
rtl_uString_newFromAscii (strError, "WSAETIMEDOUT, Connection timed out"); break;
case WSAECONNREFUSED:
rtl_uString_newFromAscii (strError, "WSAECONNREFUSED, Connection refused"); break;
case WSAEHOSTDOWN:
rtl_uString_newFromAscii (strError, "WSAEHOSTDOWN, Networking subsystem not started"); break;
case WSAEHOSTUNREACH:
rtl_uString_newFromAscii (strError, "WSAEHOSTUNREACH, No route to host"); break;
case WSAEWOULDBLOCK:
rtl_uString_newFromAscii (strError, "WSAEWOULDBLOCK, Operation would block"); break;
case WSAEINPROGRESS:
rtl_uString_newFromAscii (strError, "WSAEINPROGRESS, Operation now in progress"); break;
case WSAEALREADY:
rtl_uString_newFromAscii (strError, "WSAEALREADY, Operation already in progress"); break;
case WSAEINTR:
rtl_uString_newFromAscii (strError, "WSAEALREADY, Operation was interrupted"); break;
case WSAEBADF:
rtl_uString_newFromAscii (strError, "WSAEBADF, Bad file number"); break;
case WSAEACCES:
rtl_uString_newFromAscii (strError, "WSAEACCES, Access is denied"); break;
case WSAEFAULT:
rtl_uString_newFromAscii (strError, "WSAEFAULT, Bad memory Addr"); break;
case WSAEINVAL:
rtl_uString_newFromAscii (strError, "WSAEINVAL, The socket has not been bound with bind() or is already connected"); break;
case WSAEMFILE:
rtl_uString_newFromAscii (strError, "WSAEMFILE, No more file descriptors are available"); break;
case WSAETOOMANYREFS:
rtl_uString_newFromAscii (strError, "WSAETOOMANYREFS, Undocumented WinSock error"); break;
case WSAENAMETOOLONG:
rtl_uString_newFromAscii (strError, "WSAENAMETOOLONG, Undocumented WinSock error"); break;
case WSAENOTEMPTY:
rtl_uString_newFromAscii (strError, "WSAENOTEMPTY, Undocumented WinSock error"); break;
case WSAEPROCLIM:
rtl_uString_newFromAscii (strError, "WSAEPROCLIM, Undocumented WinSock error"); break;
case WSAEUSERS:
rtl_uString_newFromAscii (strError, "WSAEUSERS, Undocumented WinSock error"); break;
case WSAEDQUOT:
rtl_uString_newFromAscii (strError, "WSAEDQUOT, Undocumented WinSock error"); break;
case WSAESTALE:
rtl_uString_newFromAscii (strError, "WSAESTALE, Undocumented WinSock error"); break;
case WSAEREMOTE:
rtl_uString_newFromAscii (strError, "WSAEREMOTE, Undocumented WinSock error"); break;
case WSAEDISCON:
rtl_uString_newFromAscii (strError, "WSAEDISCON, Circuit was gracefully terminated"); break;
case WSASYSNOTREADY:
rtl_uString_newFromAscii (strError, "WSASYSNOTREADY, The underlying network subsystem is not ready for network communication"); break;
case WSAVERNOTSUPPORTED:
rtl_uString_newFromAscii (strError, "WSAVERNOTSUPPORTED, The version of Windows Sockets API support requested is not provided by this particular Windows Sockets implementation"); break;
case WSANOTINITIALISED:
rtl_uString_newFromAscii (strError, "WSANOTINITIALISED, WSAStartup() has not been called"); break;
case WSAHOST_NOT_FOUND:
rtl_uString_newFromAscii (strError, "WSAHOST_NOT_FOUND, Authoritative answer host not found"); break;
case WSATRY_AGAIN:
rtl_uString_newFromAscii (strError, "WSATRY_AGAIN, Non-authoritative answer host not found or SERVERFAIL"); break;
case WSANO_RECOVERY:
rtl_uString_newFromAscii (strError, "WSANO_RECOVERY, Non recoverable errors, FORMERR, REFUSED, NOTIMP"); break;
case WSANO_DATA:
rtl_uString_newFromAscii (strError, "WSANO_DATA or WSANO_ADDRESS, Valid name, no data record of requested type"); break;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.