📄 rvsocket.h
字号:
/***********************************************************************
Filename : rvsocket.h
Description: enables OS-independent BSD4.4 sockets operations.
************************************************************************
Copyright (c) 2001 RADVISION Inc.
************************************************************************
NOTICE:
This document contains information that is proprietary to RADVISION LTD.
No part of this publication may be reproduced in any form whatsoever
without written prior approval by RADVISION LTD..
RADVISION LTD. reserves the right to revise this publication and make
changes without obligation to notify any person of such revisions or
changes.
************************************************************************/
#ifndef RV_SOCKET_H
#define RV_SOCKET_H
#include "rvccore.h"
#include "rvaddress.h"
#include "rvportrange.h"
#if defined(__cplusplus)
extern "C" {
#endif
/* Error checks to make sure configuration has been done properly */
#if !defined(RV_SOCKET_TYPE) || ((RV_SOCKET_TYPE != RV_SOCKET_BSD) && \
(RV_SOCKET_TYPE != RV_SOCKET_WIN32_WSA) && (RV_SOCKET_TYPE != RV_SOCKET_PSOS) && \
(RV_SOCKET_TYPE != RV_SOCKET_NUCLEUS))
#error RV_SOCKET_TYPE not set properly
#endif
#if !defined(RV_SOCKET_HAS_IPV6) || (RV_SOCKET_HAS_IPV6 < 0) || (RV_SOCKET_HAS_IPV6 > 1)
#error RV_SOCKET_HAS_IPV6 not set properly
#endif
#if ((RV_SOCKET_HAS_IPV6 == 1) && (RV_ADDRESS_HAS_IPV6 != 1))
#error RV_SOCKET_HAS_IPV6==1 when RV_ADDRESS_HAS_IPV6==0
#endif
/* End of configuration error checks */
/* Type declaration of sockets */
#if (RV_SOCKET_TYPE == RV_SOCKET_WIN32_WSA)
#pragma warning(push, 3)
#include <winsock2.h>
#pragma warning(pop)
typedef SOCKET RvSocket;
#elif (RV_OS_TYPE == RV_OS_TYPE_WINCE)
#pragma warning(push, 3)
#include <winsock.h>
#pragma warning(pop)
typedef SOCKET RvSocket;
#else
/* Other operating systems */
typedef int RvSocket;
#endif
typedef enum
{
RvSocketProtocolUdp = 0,
RvSocketProtocolTcp
} RvSocketProtocol;
RvStatus RvSocketInit(void);
RvStatus RvSocketEnd(void);
/* =========================== */
/* ==== General functions ==== */
/* =========================== */
RVCOREAPI
RvStatus RVCALLCONV RvSocketConstruct(
IN RvSocket* sock,
IN RvInt addressType,
IN RvSocketProtocol protocolType);
/********************************************************************************************
* RvSocketBind
*
* purpose : Bind a socket to a local address
* input : socket - Socket to bind
* address - Address to bind socket to
* portRange - Port range to use if address states an ANY port.
* NULL if this parameter should be ignored.
* return : RV_OK on success, other on failure
********************************************************************************************/
RVCOREAPI
RvStatus RVCALLCONV RvSocketBind(
IN RvSocket* socket,
IN RvAddress* address,
IN RvPortRange* portRange);
RVCOREAPI
RvStatus RVCALLCONV RvSocketSetBuffers(IN RvSocket *socket, IN RvInt32 sendSize, IN RvInt32 recvSize);
/********************************************************************************************
* RvSocketSetLinger
*
* purpose : Set the linger time after socket is closed.
* input : socket - Socket to modify
* lingerTime - Time to linger in seconds
* Setting this parameter to -1 sets linger off for this socket
* output : None
* return : RV_OK on success, other on failure
********************************************************************************************/
RVCOREAPI
RvStatus RVCALLCONV RvSocketSetLinger(IN RvSocket *socket, IN RvInt32 lingerTime);
/********************************************************************************************
* RvSocketReuseAddr
*
* purpose : Set the socket as a reusable one (in terms of its address)
* This allows a TCP server socket and UDP multicast addresses to be used by
* other processes on the same machine as well.
* This function has to be called before RvSocketBind().
* input : socket - Socket to modify
* output : None
* return : RV_OK on success, other on failure
********************************************************************************************/
RVCOREAPI
RvStatus RVCALLCONV RvSocketReuseAddr(IN RvSocket *socket);
/********************************************************************************************
* RvSocketSetBlocking
*
* purpose : Set blocking/non-blocking mode on a socket
* input : socket - Socket to modify
* isBlocking - RV_TRUE for a blocking socket
* RV_FALSE for a non-blocking socket
* output : None
* return : RV_OK on success, other on failure
********************************************************************************************/
RVCOREAPI
RvStatus RVCALLCONV RvSocketSetBlocking(IN RvSocket *socket, IN RvBool isBlocking);
/********************************************************************************************
* RvSocketSetBroadcast
*
* purpose : Set permission for sending broadcast datagrams on a socket
* input : socket - Socket to modify
* canBroadcast - RV_TRUE for permitting broadcast
* RV_FALSE for not permitting broadcast
* output : None
* return : RV_OK on success, other on failure
********************************************************************************************/
RVCOREAPI
RvStatus RVCALLCONV RvSocketSetBroadcast(IN RvSocket *socket, IN RvBool canBroadcast);
/********************************************************************************************
* RvSocketSetMulticastTtl
*
* purpose : Set the TTL to use for multicast sockets (UDP)
* input : socket - Socket to modify
* ttl - TTL to set
* output : None
* return : RV_OK on success, other on failure
********************************************************************************************/
RVCOREAPI
RvStatus RVCALLCONV RvSocketSetMulticastTtl(IN RvSocket *socket, IN RvInt32 ttl);
/********************************************************************************************
* RvSocketSetMulticastInterface
*
* purpose : Set the interface to use for multicast packets (UDP)
* input : socket - Socket to modify
* address - Local address to use for the interface
* output : None
* return : RV_OK on success, other on failure
********************************************************************************************/
RVCOREAPI
RvStatus RVCALLCONV RvSocketSetMulticastInterface(IN RvSocket *socket, IN RvAddress* address);
/********************************************************************************************
* RvSocketSetTypeOfService
*
* purpose : Set the type of service (DiffServ Code Point) of the socket (IP_TOS)
* input : socket - Socket to modify
* typeOfService - type of service to set
* output : None
* return : RV_OK on success, other on failure
********************************************************************************************/
RVCOREAPI
RvStatus RVCALLCONV RvSocketSetTypeOfService(IN RvSocket *socket, IN RvInt typeOfService);
/********************************************************************************************
* RvSocketGetTypeOfService
*
* purpose : Get the type of service (DiffServ Code Point) of the socket (IP_TOS)
* input : socket - Socket to modify
* output : typeOfService - type of service to set
* return : RV_OK on success, other on failure
********************************************************************************************/
RVCOREAPI
RvStatus RVCALLCONV RvSocketGetTypeOfService(IN RvSocket *socket, IN RvInt32* typeOfService);
/********************************************************************************************
* RvSocketJoinMulticastGroup
*
* purpose : Join a multicast group
* input : socket - Socket to modify
* multicastAddress - Multicast address to join
* interfaceAddress - Interface address to use on the local host.
* Setting this to NULL chooses an arbitrary interface
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -