本文整理汇总了C++中VSocket::ReadExact方法的典型用法代码示例。如果您正苦于以下问题:C++ VSocket::ReadExact方法的具体用法?C++ VSocket::ReadExact怎么用?C++ VSocket::ReadExact使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VSocket
的用法示例。
在下文中一共展示了VSocket::ReadExact方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
BOOL
vncClientThread::InitVersion()
{
// Generate the server's protocol version
rfbProtocolVersionMsg protocolMsg;
sprintf((char *)protocolMsg,
rfbProtocolVersionFormat,
rfbProtocolMajorVersion,
rfbProtocolMinorVersion);
// Send the protocol message
if (!m_socket->SendExact((char *)&protocolMsg, sz_rfbProtocolVersionMsg))
return FALSE;
// Now, get the client's protocol version
rfbProtocolVersionMsg protocol_ver;
protocol_ver[12] = 0;
if (!m_socket->ReadExact((char *)&protocol_ver, sz_rfbProtocolVersionMsg))
return FALSE;
// Check the protocol version
int major, minor;
sscanf((char *)&protocol_ver, rfbProtocolVersionFormat, &major, &minor);
if (major != rfbProtocolMajorVersion)
return FALSE;
return TRUE;
}
示例2: vsocketDispatcher
qint64 vsocketDispatcher( char * _buf, const qint64 _len,
const SocketOpCodes _op_code, void * _user )
{
VSocket * sock = static_cast<VSocket *>( _user );
switch( _op_code )
{
case SocketRead: return( sock->ReadExact( _buf, _len ) ?
_len : 0 );
case SocketWrite: return( sock->SendExact( _buf, _len ) ?
_len : 0 );
case SocketGetPeerAddress:
strncpy( _buf, sock->GetPeerName(), _len );
return( 0 );
}
return( 0 );
}
示例3: VNCLOG
//.........这里部分代码省略.........
// Initial negotiation is complete, so set the protocol ready flag
m_client->EnableProtocol();
// Add a fullscreen update to the client's update list
{ omni_mutex_lock l(m_client->GetUpdateLock());
m_client->m_update_tracker.add_changed(m_client->m_fullscreen);
}
// Clear the CapsLock and NumLock keys
if (m_client->m_keyboardenabled)
{
ClearKeyState(VK_CAPITAL);
// *** JNW - removed because people complain it's wrong
//ClearKeyState(VK_NUMLOCK);
ClearKeyState(VK_SCROLL);
}
// MAIN LOOP
// Set the input thread to a high priority
set_priority(omni_thread::PRIORITY_HIGH);
BOOL connected = TRUE;
while (connected)
{
rfbClientToServerMsg msg;
// Ensure that we're running in the correct desktop
if (!vncService::InputDesktopSelected())
if (!vncService::SelectDesktop(NULL))
break;
// Try to read a message ID
if (!m_socket->ReadExact((char *)&msg.type, sizeof(msg.type)))
{
connected = FALSE;
break;
}
// What to do is determined by the message id
switch(msg.type)
{
case rfbSetPixelFormat:
// Read the rest of the message:
if (!m_socket->ReadExact(((char *) &msg)+1, sz_rfbSetPixelFormatMsg-1))
{
connected = FALSE;
break;
}
// Swap the relevant bits.
msg.spf.format.redMax = Swap16IfLE(msg.spf.format.redMax);
msg.spf.format.greenMax = Swap16IfLE(msg.spf.format.greenMax);
msg.spf.format.blueMax = Swap16IfLE(msg.spf.format.blueMax);
// Prevent updates while the pixel format is changed
m_client->DisableProtocol();
// Tell the buffer object of the change
if (!m_client->m_encodemgr.SetClientFormat(msg.spf.format))
{
vnclog.Print(LL_CONNERR, VNCLOG("remote pixel format invalid\n"));
connected = FALSE;
}
示例4: plain
//.........这里部分代码省略.........
if (!m_socket->SendExact((char *)&errlen, sizeof(errlen)))
return FALSE;
m_socket->SendExact(errmsg, strlen(errmsg));
return FALSE;
}
}
}
// Authenticate the connection, if required
if (m_auth || (strlen(plain) == 0))
{
// Send no-auth-required message
CARD32 auth_val = Swap32IfLE(rfbNoAuth);
if (!m_socket->SendExact((char *)&auth_val, sizeof(auth_val)))
return FALSE;
}
else
{
// Send auth-required message
CARD32 auth_val = Swap32IfLE(rfbVncAuth);
if (!m_socket->SendExact((char *)&auth_val, sizeof(auth_val)))
return FALSE;
BOOL auth_ok = TRUE;
{
// Now create a 16-byte challenge
char challenge[16];
vncRandomBytes((BYTE *)&challenge);
// Send the challenge to the client
if (!m_socket->SendExact(challenge, sizeof(challenge)))
return FALSE;
// Read the response
char response[16];
if (!m_socket->ReadExact(response, sizeof(response)))\
return FALSE;
// Encrypt the challenge bytes
vncEncryptBytes((BYTE *)&challenge, plain);
// Compare them to the response
for (int i=0; i<sizeof(challenge); i++)
{
if (challenge[i] != response[i])
{
auth_ok = FALSE;
break;
}
}
}
// Did the authentication work?
CARD32 authmsg;
if (!auth_ok)
{
vnclog.Print(LL_CONNERR, VNCLOG("authentication failed\n"));
authmsg = Swap32IfLE(rfbVncAuthFailed);
m_socket->SendExact((char *)&authmsg, sizeof(authmsg));
return FALSE;
}
else
{
// Tell the client we're ok
authmsg = Swap32IfLE(rfbVncAuthOK);
if (!m_socket->SendExact((char *)&authmsg, sizeof(authmsg)))
return FALSE;
}
}
// Read the client's initialisation message
rfbClientInitMsg client_ini;
if (!m_socket->ReadExact((char *)&client_ini, sz_rfbClientInitMsg))
return FALSE;
// If the client wishes to have exclusive access then remove other clients
if (!client_ini.shared && !m_shared)
{
// Which client takes priority, existing or incoming?
if (m_server->ConnectPriority() < 1)
{
// Incoming
vnclog.Print(LL_INTINFO, VNCLOG("non-shared connection - disconnecting old clients\n"));
m_server->KillAuthClients();
} else if (m_server->ConnectPriority() > 1)
{
// Existing
if (m_server->AuthClientCount() > 0)
{
vnclog.Print(LL_CLIENTS, VNCLOG("connections already exist - client rejected\n"));
return FALSE;
}
}
}
// Tell the server that this client is ok
return m_server->Authenticated(m_client->GetClientId());
}