本文整理汇总了C++中Read函数的典型用法代码示例。如果您正苦于以下问题:C++ Read函数的具体用法?C++ Read怎么用?C++ Read使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Read函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例2: Read
size_t Read(T* t) { return Read(t, sizeof(T)); }
示例3: Write
bool CGPIBDevice::Query(const char *sWrite, int &nLen, char *sRead, int nTimeout)
{
return Write(sWrite) && Read(sRead, nLen, nTimeout);
}
示例4: strlen
bool CMgProxySocket::DoV5Connect( const char* server , int port )
{
unsigned char buf[ 512 ];
buf[ 0 ] = 0x05;
buf[ 1 ] = 0x01; //connect
buf[ 2 ] = 0x00; //reserve
buf[ 3 ] = 0x03;
buf[ 4 ] = strlen( server );
memcpy( buf + 5, server, strlen( server ) );
int pos = 5 + buf[ 4 ];
short sport = htons( ( short ) port );
memcpy( buf + pos, &sport, 2 );
pos += 2;
if ( !Send( buf, pos ) )
{
m_nLastError += ( 0x1A << 8 );
return false;
}
int nret = Read( buf, 512 );
if ( nret <= 0 )
{
m_nLastError += ( 0x1B << 8 );
return false;
}
if ( nret < 10 )
{
m_nLastError = ( 0x0F << 8 );
return false;
}
if ( buf[ 0 ] != 0x05 || buf[ 2 ] != 0x00 )
{
m_nLastError = ( 0x10 << 8 );
return false;
}
/*
# X'00' success
# X'01' fail
# X'02' not allow
# X'03' net unreach
# X'04' host unreach
# X'05' connect refuse
# X'06' TTL timeout
# X'07' not support command
# X'08' not support address
# X'09' – X'FF' undef
*/
if ( buf[ 1 ] == 0 )
{
return true;
}
else if ( buf[ 1 ] == 0x01 )
{
m_nLastError = ( 0x11 << 8 );
return false;
}
else if ( buf[ 1 ] == 0x02 )
{
m_nLastError = ( 0x12 << 8 );
return false;
}
else if ( buf[ 1 ] == 0x03 )
{
m_nLastError = ( 0x13 << 8 );
return false;
}
else if ( buf[ 1 ] == 0x04 )
{
m_nLastError = ( 0x14 << 8 );
return false;
}
else if ( buf[ 1 ] == 0x05 )
{
m_nLastError = ( 0x15 << 8 );
return false;
}
else if ( buf[ 1 ] == 0x06 )
{
m_nLastError = ( 0x16 << 8 );
return false;
}
else if ( buf[ 1 ] == 0x07 )
{
m_nLastError = ( 0x17 << 8 );
return false;
}
else if ( buf[ 1 ] == 0x08 )
{
m_nLastError = ( 0x18 << 8 );
return false;
}
else
{
m_nLastError = ( 0x19 << 8 );
//.........这里部分代码省略.........
示例5: Read
bool CMgProxySocket::DoV5Login()
{
unsigned char init[ 4 ] = {0x05, 0x02, 0x00, 0x02};
if ( !Send( init, 4 ) )
{
m_nLastError = ( 0x03 << 8 );
return false;
}
unsigned char buf[ 256 ];
int nret = Read( buf, 256 );
if ( nret != 2 )
{
m_nLastError = ( 0x04 << 8 );
return false;
}
if ( buf[ 0 ] != 0x05 )
{
m_nLastError = ( 0x05 << 8 );
return false;
}
if ( buf[ 1 ] == 0xFF )
{
m_nLastError = ( 0x06 << 8 );
return false;
}
if ( buf[ 1 ] != 0 && buf[ 1 ] != 1 && buf[ 1 ] != 2 )
{
m_nLastError = ( 0x07 << 8 );
return false;
}
if ( buf[ 1 ] == 0 )
{ //ok
return true;
}
else if ( buf[ 1 ] == 1 )
{ //GSSAPI
m_nLastError = ( 0x08 << 8 );
return false;
}
else
{ //u/p
int tl = 0;
buf[ 0 ] = 0x01;
tl++;
buf[ tl ] = m_ProxyUser.length();
tl++;
memcpy( buf + tl, m_ProxyUser.c_str(), m_ProxyUser.length() );
tl += m_ProxyUser.length();
buf[ tl ] = m_ProxyPass.length();
tl++;
memcpy( buf + tl, m_ProxyPass.c_str(), m_ProxyPass.length() );
tl += m_ProxyPass.length();
if ( !Send( buf, tl ) )
{
m_nLastError += ( 0x09 << 8 );
return false;
}
if ( Read( buf, 256 ) != 2 )
{
m_nLastError = ( 0x0A << 8 );
return false;
}
if ( buf[ 0 ] != 0x01 )
{
m_nLastError = ( 0x0B << 8 );
return false;
}
if ( buf[ 1 ] != 0x00 )
{
m_nLastError = ( 0x0C << 8 );
return false;
}
return true;
}
return false;
}
示例6: main
int
main( int argc, char **argv )
{
int listenfd, connfd, sockfd;
int client[FD_SETSIZE];
int i, maxfd, maxi, nready;
socklen_t clilen;
ssize_t n;
char buff[MAXLINE];
struct sockaddr_in servaddr, cliaddr;
fd_set rset, allset;
listenfd = Socket( AF_INET, SOCK_STREAM, 0 );
bzero( &servaddr, sizeof( servaddr ) );
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl( INADDR_ANY );
servaddr.sin_port = htons( SERV_PORT );
Bind( listenfd, ( struct sockaddr * )&servaddr, sizeof( servaddr ) );
Listen( listenfd, 10 );
maxfd = listenfd;
maxi = -1;
for ( i = 0; i < FD_SETSIZE; i++ ) {
client[i] = -1;
}
FD_ZERO( &allset );
FD_SET( listenfd, &allset );
for ( ; ; ) {
rset = allset;
nready = Select( maxfd+1, &rset, NULL, NULL, NULL );
if ( FD_ISSET( listenfd, &rset ) ) {
clilen = sizeof( cliaddr );
connfd = Accept( listenfd, ( struct sockaddr * )&cliaddr, &clilen );
for ( i = 0; i < FD_SETSIZE; i++ ) {
if ( client[i] < 0 ) {
client[i] = connfd;
break;
}
}
if ( i == FD_SETSIZE )
err_quit( "too many clients" );
FD_SET( connfd, &allset );
if ( connfd > maxfd )
maxfd = connfd;
if ( i > maxi )
maxi = i;
if ( --nready <= 0 )
continue;
}
for ( i = 0; i <= maxi; i++ ) {
if ( ( sockfd = client[i] ) < 0 )
continue;
if ( FD_ISSET( sockfd, &rset ) ) {
if ( ( n = Read( sockfd, buff, MAXLINE ) ) == 0 ) {
close( sockfd );
FD_CLR( sockfd, &allset );
client[i] = -1;
} else
writen( sockfd, buff, n );
if ( --nready <= 0 )
break;
}
}
}
}
示例7: while
int CSocketServer::WorkerThread::Run()
{
try
{
while ( true )
{
/*
* Continually loop to service io completion packets
*/
bool closeSocket = false;
DWORD dwIoSize = 0;
Socket *pSocket = 0;
CIOBuffer *pBuffer = 0;
try
{
m_iocp.GetStatus( (PDWORD_PTR)&pSocket, &dwIoSize, (OVERLAPPED **)&pBuffer );
}
catch (const CWin32Exception &e)
{
if ( e.GetError() != ERROR_NETNAME_DELETED &&
e.GetError() != WSA_OPERATION_ABORTED )
{
throw;
}
Output( _T("IOCP error [client connection dropped] - ") +
GetLastErrorMessage( ::WSAGetLastError() ) );
closeSocket = true;
}
if ( !pSocket )
{
/*
* A completion key of 0 is posted to the iocp to request us to shut down...
*/
break;
}
/*
* Call to unqualified virtual function
*/
OnBeginProcessing();
if ( pBuffer )
{
const IO_Operation operation = static_cast<IO_Operation>( pBuffer->GetUserData() );
switch ( operation )
{
case IO_Read_Request:
Read( pSocket, pBuffer );
break;
case IO_Read_Completed :
if ( 0 != dwIoSize )
{
pBuffer->Use( dwIoSize );
//DEBUG_ONLY( Output(_T("RX: ") + ToString(pBuffer) + _T("\n") + DumpData(reinterpret_cast<const BYTE*>( pBuffer->GetWSABUF()->buf), dwIoSize, 40) ) );
/*
* Call to unqualified virtual function
*/
ReadCompleted( pSocket, pBuffer );
}
else
{
/*
* client connection dropped...
*/
Output( _T("ReadCompleted - 0 bytes - client connection dropped") );
closeSocket = true;
}
pSocket->Release();
pBuffer->Release();
break;
case IO_Write_Request :
Write( pSocket, pBuffer );
if ( dwIoSize != 0 )
{
/*
* final write, now shutdown send side of connection
*/
pSocket->Shutdown( SD_SEND );
}
//.........这里部分代码省略.........
示例8: Read
uint In::Read16()
{
byte data[2];
Read( data, 2 );
return data[0] | uint(data[1]) << 8;
}
示例9: GetPos
int Buffer::Peek() {
int curPos = GetPos();
int ch = Read();
SetPos(curPos);
return ch;
}
示例10: HistoryFrames
FStatsThreadState::FStatsThreadState( FString const& Filename )
: HistoryFrames( MAX_int32 )
, MaxFrameSeen( -1 )
, MinFrameSeen( -1 )
, LastFullFrameMetaAndNonFrame( -1 )
, LastFullFrameProcessed( -1 )
, bWasLoaded( true )
, CurrentGameFrame( -1 )
, CurrentRenderFrame( -1 )
{
const int64 Size = IFileManager::Get().FileSize( *Filename );
if( Size < 4 )
{
UE_LOG( LogStats, Error, TEXT( "Could not open: %s" ), *Filename );
return;
}
TAutoPtr<FArchive> FileReader( IFileManager::Get().CreateFileReader( *Filename ) );
if( !FileReader )
{
UE_LOG( LogStats, Error, TEXT( "Could not open: %s" ), *Filename );
return;
}
FStatsReadStream Stream;
if( !Stream.ReadHeader( *FileReader ) )
{
UE_LOG( LogStats, Error, TEXT( "Could not open, bad magic: %s" ), *Filename );
return;
}
// Test version only works for the finalized stats files.
const bool bIsFinalized = Stream.Header.IsFinalized();
check( bIsFinalized );
TArray<FStatMessage> Messages;
if( Stream.Header.bRawStatsFile )
{
const int64 CurrentFilePos = FileReader->Tell();
// Read metadata.
TArray<FStatMessage> MetadataMessages;
Stream.ReadFNamesAndMetadataMessages( *FileReader, MetadataMessages );
ProcessMetaDataForLoad( MetadataMessages );
// Read frames offsets.
Stream.ReadFramesOffsets( *FileReader );
// Verify frames offsets.
for( int32 FrameIndex = 0; FrameIndex < Stream.FramesInfo.Num(); ++FrameIndex )
{
const int64 FrameFileOffset = Stream.FramesInfo[FrameIndex].FrameFileOffset;
FileReader->Seek( FrameFileOffset );
int64 TargetFrame;
*FileReader << TargetFrame;
}
FileReader->Seek( Stream.FramesInfo[0].FrameFileOffset );
// Read the raw stats messages.
FStatPacketArray IncomingData;
for( int32 FrameIndex = 0; FrameIndex < Stream.FramesInfo.Num(); ++FrameIndex )
{
int64 TargetFrame;
*FileReader << TargetFrame;
int32 NumPackets;
*FileReader << NumPackets;
for( int32 PacketIndex = 0; PacketIndex < NumPackets; PacketIndex++ )
{
FStatPacket* ToRead = new FStatPacket();
Stream.ReadStatPacket( *FileReader, *ToRead, bIsFinalized );
IncomingData.Packets.Add( ToRead );
}
FStatPacketArray NowData;
// This is broken, do not use.
// Exchange( NowData.Packets, IncomingData.Packets );
// ScanForAdvance( NowData );
// AddToHistoryAndEmpty( NowData );
// check( !NowData.Packets.Num() );
}
}
else
{
// Read the condensed stats messages.
while( FileReader->Tell() < Size )
{
FStatMessage Read( Stream.ReadMessage( *FileReader ) );
if( Read.NameAndInfo.GetField<EStatOperation>() == EStatOperation::SpecialMessageMarker )
{
// Simply break the loop.
// The profiler supports more advanced handling of this message.
break;
}
else if( Read.NameAndInfo.GetField<EStatOperation>() == EStatOperation::AdvanceFrameEventGameThread )
{
ProcessMetaDataForLoad( Messages );
if( CurrentGameFrame > 0 && Messages.Num() )
{
//.........这里部分代码省略.........
示例11: Read
T Read()
{
T x;
Read(&x, sizeof(T));
return x;
}
示例12: CacheRead
long CacheRead( CICell ih, char * buffer, long long offset,
long length, long cache )
{
long cnt, oldestEntry = 0, oldestTime, loadCache = 0;
CacheEntry *entry;
// See if the data can be cached.
if (cache && (gCacheIH == ih) && (length == gCacheBlockSize)) {
// Look for the data in the cache.
for (cnt = 0; cnt < gCacheNumEntries; cnt++) {
entry = &gCacheEntries[cnt];
if ((entry->ih == ih) && (entry->offset == offset)) {
entry->time = ++gCacheTime;
break;
}
}
// If the data was found copy it to the caller.
if (cnt != gCacheNumEntries) {
bcopy(gCacheBuffer + cnt * gCacheBlockSize, buffer, gCacheBlockSize);
#if CACHE_STATS
gCacheHits++;
#endif
return gCacheBlockSize;
}
// Could not find the data in the cache.
loadCache = 1;
}
// Read the data from the disk.
Seek(ih, offset);
Read(ih, (long)buffer, length);
#if CACHE_STATS
if (cache) gCacheMisses++;
#endif
// Put the data from the disk in the cache if needed.
if (loadCache) {
// Find a free entry.
oldestTime = gCacheTime;
for (cnt = 0; cnt < gCacheNumEntries; cnt++) {
entry = &gCacheEntries[cnt];
// Found a free entry.
if (entry->ih == 0) break;
if (entry->time < oldestTime) {
oldestTime = entry->time;
oldestEntry = cnt;
}
}
// If no free entry was found, use the oldest.
if (cnt == gCacheNumEntries) {
cnt = oldestEntry;
#if CACHE_STATS
gCacheEvicts++;
#endif
}
// Copy the data from disk to the new entry.
entry = &gCacheEntries[cnt];
entry->ih = ih;
entry->time = ++gCacheTime;
entry->offset = offset;
bcopy(buffer, gCacheBuffer + cnt * gCacheBlockSize, gCacheBlockSize);
}
return length;
}
示例13: RAWRead
bool CVolumeWiiCrypted::CheckIntegrity() const
{
// Get partition data size
u32 partSizeDiv4;
RAWRead(m_VolumeOffset + 0x2BC, 4, (u8*)&partSizeDiv4);
u64 partDataSize = (u64)Common::swap32(partSizeDiv4) * 4;
u32 nClusters = (u32)(partDataSize / 0x8000);
for (u32 clusterID = 0; clusterID < nClusters; ++clusterID)
{
u64 clusterOff = m_VolumeOffset + dataOffset + (u64)clusterID * 0x8000;
// Read and decrypt the cluster metadata
u8 clusterMDCrypted[0x400];
u8 clusterMD[0x400];
u8 IV[16] = { 0 };
if (!m_pReader->Read(clusterOff, 0x400, clusterMDCrypted))
{
NOTICE_LOG(DISCIO, "Integrity Check: fail at cluster %d: could not read metadata", clusterID);
return false;
}
aes_crypt_cbc(m_AES_ctx, AES_DECRYPT, 0x400, IV, clusterMDCrypted, clusterMD);
// Some clusters have invalid data and metadata because they aren't
// meant to be read by the game (for example, holes between files). To
// try to avoid reporting errors because of these clusters, we check
// the 0x00 paddings in the metadata.
//
// This may cause some false negatives though: some bad clusters may be
// skipped because they are *too* bad and are not even recognized as
// valid clusters. To be improved.
bool meaningless = false;
for (u32 idx = 0x26C; idx < 0x280; ++idx)
if (clusterMD[idx] != 0)
meaningless = true;
if (meaningless)
continue;
u8 clusterData[0x7C00];
if (!Read((u64)clusterID * 0x7C00, 0x7C00, clusterData))
{
NOTICE_LOG(DISCIO, "Integrity Check: fail at cluster %d: could not read data", clusterID);
return false;
}
for (u32 hashID = 0; hashID < 31; ++hashID)
{
u8 hash[20];
sha1(clusterData + hashID * 0x400, 0x400, hash);
// Note that we do not use strncmp here
if (memcmp(hash, clusterMD + hashID * 20, 20))
{
NOTICE_LOG(DISCIO, "Integrity Check: fail at cluster %d: hash %d is invalid", clusterID, hashID);
return false;
}
}
}
return true;
}
示例14: Log
bool Archive::IsArchive(bool EnableBroken)
{
Encrypted=false;
#ifndef SFX_MODULE
if (IsDevice())
{
#ifndef SHELL_EXT
Log(FileName,St(MInvalidName),FileName);
#endif
return(false);
}
#endif
if (Read(MarkHead.Mark,SIZEOF_MARKHEAD)!=SIZEOF_MARKHEAD)
return(false);
SFXSize=0;
ARCSIGN_TYPE Type;
if ((Type=IsSignature(MarkHead.Mark,sizeof(MarkHead.Mark)))!=ARCSIGN_NONE)
{
OldFormat=(Type==ARCSIGN_OLD);
if (OldFormat)
Seek(0,SEEK_SET);
}
else
{
Array<char> Buffer(MAXSFXSIZE);
long CurPos=(long)Tell();
int ReadSize=Read(&Buffer[0],Buffer.Size()-16);
for (int I=0;I<ReadSize;I++)
if (Buffer[I]==0x52 && (Type=IsSignature((byte *)&Buffer[I],ReadSize-I))!=ARCSIGN_NONE)
{
OldFormat=(Type==ARCSIGN_OLD);
if (OldFormat && I>0 && CurPos<28 && ReadSize>31)
{
char *D=&Buffer[28-CurPos];
if (D[0]!=0x52 || D[1]!=0x53 || D[2]!=0x46 || D[3]!=0x58)
continue;
}
SFXSize=CurPos+I;
Seek(SFXSize,SEEK_SET);
if (!OldFormat)
Read(MarkHead.Mark,SIZEOF_MARKHEAD);
break;
}
if (SFXSize==0)
return false;
}
if (Type==ARCSIGN_FUTURE)
{
#if !defined(SHELL_EXT) && !defined(SFX_MODULE)
Log(FileName,St(MNewRarFormat));
#endif
return false;
}
ReadHeader();
SeekToNext();
#ifndef SFX_MODULE
if (OldFormat)
{
NewMhd.Flags=OldMhd.Flags & 0x3f;
NewMhd.HeadSize=OldMhd.HeadSize;
}
else
#endif
{
if (HeaderCRC!=NewMhd.HeadCRC)
{
#ifndef SHELL_EXT
Log(FileName,St(MLogMainHead));
#endif
Alarm();
if (!EnableBroken)
return(false);
}
}
Volume=(NewMhd.Flags & MHD_VOLUME);
Solid=(NewMhd.Flags & MHD_SOLID)!=0;
MainComment=(NewMhd.Flags & MHD_COMMENT)!=0;
Locked=(NewMhd.Flags & MHD_LOCK)!=0;
Signed=(NewMhd.PosAV!=0);
Protected=(NewMhd.Flags & MHD_PROTECT)!=0;
Encrypted=(NewMhd.Flags & MHD_PASSWORD)!=0;
if (NewMhd.EncryptVer>UNP_VER)
{
#ifdef RARDLL
Cmd->DllError=ERAR_UNKNOWN_FORMAT;
#else
ErrHandler.SetErrorCode(RARX_WARNING);
#if !defined(SILENT) && !defined(SFX_MODULE)
Log(FileName,St(MUnknownMeth),FileName);
Log(FileName,St(MVerRequired),NewMhd.EncryptVer/10,NewMhd.EncryptVer%10);
#endif
#endif
return(false);
}
#ifdef RARDLL
// If callback function is not set, we cannot get the password,
// so we skip the initial header processing for encrypted header archive.
// It leads to skipped archive comment, but the rest of archive data
//.........这里部分代码省略.........
示例15: C32LOG5
void CCommSession::ServiceL(const RMessage2& aMessage)
/**
* Handle messages for this session.
*
* @param aMessage handle to the IPC message from the client
*/
{
C32LOG5(KC32Detail,_L8("CCommSession::ServiceL(), Session : 0x%x, IPC: %d (%S). Message: %08x"), this, aMessage.Function(), &TC32Log::C32RequestStr(aMessage.Function()),aMessage.Handle());
iComplete = ETrue;
const CC32WorkerThread& owner=C32WorkerThread();
CC32Dealer& c32Dealer = owner.DealerByRef();
if (c32Dealer.StartupFailed())
{
SafeComplete(aMessage, KErrNotReady);
return;
}
// TestImmediateShutdownPresent is only set when EImmediate shutdown is present, which is
// used only in testing phase.
if(c32Dealer.TestImmediateShutdownPresent())
{
User::Leave(KErrServerTerminated);
}
if((aMessage.Function()==ECommOpen)
||
(aMessage.Function()==ECommOpenWhenAvailable))
{
NewPortL(aMessage);
return;
}
#if defined (_DEBUG)
switch (aMessage.Function())
{
case ECommDbgMarkHeap:
__UHEAP_MARK;
SafeComplete(aMessage, KErrNone);
return;
case ECommDbgCheckHeap:
__UHEAP_CHECK(aMessage.Int0());
SafeComplete(aMessage, KErrNone);
return;
case ECommDbgMarkEnd:
__UHEAP_MARKENDC(aMessage.Int0());
SafeComplete(aMessage, KErrNone);
return;
case ECommDbgFailNext:
// We set the fail point for all heaps, rather than just the current Dealer. This could lead to a failure not related
// directly to whatever the client test code is trying to exercise but it all helps find bugs
c32Dealer.SetFailNextForAllHeaps(aMessage.Int0());
SafeComplete(aMessage, KErrNone);
return;
}
#endif
switch ((aMessage.Function()))
{
case ECommLoadCommModule:
{
TFileName fullCSYFilename;
TInt ret = Read(0,aMessage,fullCSYFilename);
if (ret != KErrNone)
{
C32LOG2(KC32Warning, _L8("ServiceL: LoadCommModule Read returned %d instead of KErrNone, cannot proceed"), ret);
PanicClient(EBadDescriptor,aMessage);
return;
}
ret = AddCSYExtension(fullCSYFilename,aMessage);
if(ret != KErrNone)
{
C32LOG2(KC32Warning, _L8("ServiceL: LoadCommModule AddCSYExtension returned %d instead of KErrNone, cannot proceed"), ret);
return;
}
CommsFW::TWorkerId worker;
TBuf8<KMaxFileName> fileName8;
fileName8.Copy(fullCSYFilename);
TBool found = iThreadManager->FindThreadByFileName(fileName8, worker);
if(!found)
{
worker = iThreadManager->iDefaultThreadIndex;
}
if(c32Dealer.WorkerExists(worker))
{
LoadCommModuleL(aMessage,worker,!found,fullCSYFilename);
}
else
{
C32LOG2(KC32Dealer,_L8("ServiceL: LoadCommModule requires worker %d. This worker does not exist so starting"),worker);
ret = c32Dealer.LoadCPMOnLoadCommModule(worker);
if ((ret!=KErrNone) && (ret!=KErrInUse))
{
// only likely return codes here are KErrNoMemory or KErrNotFound if
// the RS server could not be found - which means system is probably in pretty bad state (ie, no memory)
//.........这里部分代码省略.........