Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/external/source/vncdll/winvnc/VSocket.h
Views: 11778
// Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.1// Copyright (C) 2001 HorizonLive.com, Inc. All Rights Reserved.2//3// This file is part of the VNC system.4//5// The VNC system is free software; you can redistribute it and/or modify6// it under the terms of the GNU General Public License as published by7// the Free Software Foundation; either version 2 of the License, or8// (at your option) any later version.9//10// This program is distributed in the hope that it will be useful,11// but WITHOUT ANY WARRANTY; without even the implied warranty of12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13// GNU General Public License for more details.14//15// You should have received a copy of the GNU General Public License16// along with this program; if not, write to the Free Software17// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,18// USA.19//20// TightVNC distribution homepage on the Web: http://www.tightvnc.com/21//22// If the source code for the VNC system is not available from the place23// whence you received this file, check http://www.uk.research.att.com/vnc or contact24// the authors on [email protected] for information on obtaining it.252627// VSocket.h2829// RFB V3.03031// The VSocket class provides simple socket functionality,32// independent of platform. Hurrah.3334class VSocket;3536#if (!defined(_ATT_VSOCKET_DEFINED))37#define _ATT_VSOCKET_DEFINED3839#include <omnithread.h>40#include "VTypes.h"4142// This class is used as a part of output queue43class AIOBlock44{45public:46size_t data_size; // Data size in this block47char *data_ptr; // Beginning of the data buffer48AIOBlock *next; // Next block or NULL for the last block4950AIOBlock(int size, const char *data = NULL) {51next = NULL;52data_size = size;53data_ptr = new char[size];54if (data_ptr && data)55memcpy(data_ptr, data, size);56}57~AIOBlock() {58if (data_ptr)59delete[] data_ptr;60}61};6263////////////////////////////64// Socket implementation6566// Create one or more VSocketSystem objects per application67class VSocketSystem68{69public:70VSocketSystem();71~VSocketSystem();72VBool Initialised() {return m_status;};73private:74VBool m_status;75};7677// The main socket class78class VSocket79{80public:81// Constructor/Destructor82VSocket();83VSocket( WSAPROTOCOL_INFO * pSocketInfo, HANDLE hClose );84virtual ~VSocket();8586////////////////////////////87// Socket implementation8889// Create90// Create a socket and attach it to this VSocket object91VBool Create();9293// Shutdown94// Shutdown the currently attached socket95VBool Shutdown();9697// Close98// Close the currently attached socket99VBool Close();100101// Bind102// Bind the attached socket to the specified port103// If localOnly is VTrue then the socket is bound only104// to the loopback adapter. If checkIfInUse is VTrue,105// then the socket won't be bound to an address which106// is already in use (i.e. accepts connections).107VBool Bind(const VCard port, const VBool localOnly = VFalse,108const VBool checkIfInUse = VFalse);109110// Connect111// Make a stream socket connection to the specified port112// on the named machine.113VBool Connect(VStringConst address, const VCard port);114115// Listen116// Set the attached socket to listen for connections117VBool Listen();118119// Accept120// If the attached socket is set to listen then this121// call blocks waiting for an incoming connection, then122// returns a new socket object for the new connection123VSocket *Accept();124125// TryAccept126// Non-blocking version of Accept. It waits for an127// incoming connection only for the specified number of128// milliseconds. It returns VFalse on error, otherwise stores129// either pointer to the new VSocket, or NULL on timeout130VBool TryAccept(VSocket **new_socket, long ms);131132// GetPeerName133// If the socket is connected then this returns the name134// of the machine to which it is connected.135// This string MUST be copied before the next socket call...136VString GetPeerName();137138// GetSockName139// If the socket exists then the name of the local machine140// is returned. This string MUST be copied before the next141// socket call!142VString GetSockName();143144// Resolve145// Uses the Winsock API to resolve the supplied DNS name to146// an IP address and returns it as an Int32147static VCard32 Resolve(VStringConst name);148149// SetTimeout150// Sets the socket timeout on reads and writes.151VBool SetTimeout(VCard32 secs);152153// I/O routines154155// Send and Read return the number of bytes sent or recieved.156VInt Send(const char *buff, const VCard bufflen);157VInt Read(char *buff, const VCard bufflen);158159// SendExact and ReadExact attempt to send and recieve exactly160// the specified number of bytes.161VBool SendExact(const char *buff, const VCard bufflen);162VBool ReadExact(char *buff, const VCard bufflen);163164// SendQueued sends as much data as possible immediately,165// and puts remaining bytes in a queue, to be sent later.166VBool SendQueued(const char *buff, const VCard bufflen);167168////////////////////////////169// Internal structures170protected:171// The internal socket id172int sock;173HANDLE hCloseEvent;174175// Output queue176size_t bytes_sent;177AIOBlock *out_queue;178omni_mutex queue_lock;179180VBool SendFromQueue();181};182183#endif // _ATT_VSOCKET_DEFINED184185186