void cChunkSender::Execute(void) { while (!m_ShouldTerminate) { cCSLock Lock(m_CS); while (m_ChunksReady.empty() && m_SendChunks.empty()) { int RemoveCount = m_RemoveCount; m_RemoveCount = 0; cCSUnlock Unlock(Lock); for (int i = 0; i < RemoveCount; i++) { m_evtRemoved.Set(); // Notify that the removed clients are safe to be deleted } m_evtQueue.Wait(); if (m_ShouldTerminate) { return; } } // while (empty) if (!m_ChunksReady.empty()) { // Take one from the queue: cChunkCoords Coords(m_ChunksReady.front()); m_ChunksReady.pop_front(); Lock.Unlock(); SendChunk(Coords.m_ChunkX, Coords.m_ChunkY, Coords.m_ChunkZ, NULL); } else { // Take one from the queue: sSendChunk Chunk(m_SendChunks.front()); m_SendChunks.pop_front(); Lock.Unlock(); SendChunk(Chunk.m_ChunkX, Chunk.m_ChunkY, Chunk.m_ChunkZ, Chunk.m_Client); } Lock.Lock(); int RemoveCount = m_RemoveCount; m_RemoveCount = 0; Lock.Unlock(); for (int i = 0; i < RemoveCount; i++) { m_evtRemoved.Set(); // Notify that the removed clients are safe to be deleted } } // while (!mShouldTerminate) }
void SQDbgServer::EndElement(const SQChar *name) { XMLElementState *self = &xmlstate[_xmlcurrentement]; assert(scstrcmp(self->name,name) == 0); if(self->haschildren) { _scratchstring.resize(4+scstrlen(name)); scsprintf(&_scratchstring[0],_SC("</%s>"),name); SendChunk(&_scratchstring[0]); } else { SendChunk(_SC("/>")); } _xmlcurrentement--; }
// Fill the transmission window BOOL CDataTransfer::FillWindow() { DWORD moreData = UntransferredDataAmount(); DWORD freeSpace = FreeWindowSpace(); while(freeSpace && moreData) { DWORD chunkSize = m_chunkSize; if (chunkSize > moreData) chunkSize = moreData; if (chunkSize > freeSpace) chunkSize = freeSpace; if (!SendChunk(m_data, chunkSize)) return FALSE; m_data += chunkSize; m_transferred += chunkSize; moreData = UntransferredDataAmount(); freeSpace = FreeWindowSpace(); } return TRUE; }
void SQDbgServer::SerializeState() { sq_pushnull(_v); sq_setdebughook(_v); sq_pushnull(_v); sq_seterrorhandler(_v); const SQChar *sz; sq_pushobject(_v,_serializefunc); sq_pushobject(_v,_debugroot); sq_pushstring(_v,_SC("watches"),-1); sq_newtable(_v); for(WatchSetItor i=_watches.begin(); i!=_watches.end(); ++i) { sq_pushinteger(_v,i->_id); sq_pushstring(_v,i->_exp.c_str(),(int)i->_exp.length()); sq_createslot(_v,-3); } sq_rawset(_v,-3); if(SQ_SUCCEEDED(sq_call(_v,1,SQTrue,SQTrue))){ if(SQ_SUCCEEDED(sqstd_getblob(_v,-1,(SQUserPointer*)&sz))) SendChunk(sz); } sq_pop(_v,2); SetErrorHandlers(); }
bool SenderThread::OnJob() { Job j = m_jQueue->Pop(); switch(j.m_Type) { case Job::THREAD_SEND_CHUNK_WITH_POLICY_ID: return SendChunkWithPolicy((Policy*)j.m_Arg); break; case Job::THREAD_SEND_CHUNK_ID: return SendChunk(); break; case Job::THREAD_EXIT_ID: // thread should exit printf("GAVDGAVDGASVDGASVDGASVDGVASDGVAGDVGADVADVASDVGASDV\n"); delete m_jQueue; m_Socket->Destroy(); return false; break; default: delete m_jQueue; //Mo way! return false; break; } // switch(j.m_Type) return false; }
void SQDbgServer::BeginElement(const SQChar *name) { _xmlcurrentement++; XMLElementState *self = &xmlstate[_xmlcurrentement]; scstrcpy(self->name,name); self->haschildren = false; if(_xmlcurrentement > 0) { XMLElementState *parent = &xmlstate[_xmlcurrentement-1]; if(!parent->haschildren) { SendChunk(_SC(">")); // closes the parent tag parent->haschildren = true; } } _scratchstring.resize(2+scstrlen(name)); scsprintf(&_scratchstring[0],_SC("<%s"),name); SendChunk(&_scratchstring[0]); }
void SQDbgServer::Attribute(const SQChar *name,const SQChar *value) { XMLElementState *self = &xmlstate[_xmlcurrentement]; assert(!self->haschildren); //cannot have attributes if already has children const SQChar *escval = escape_xml(value); _scratchstring.resize(5+scstrlen(name)+scstrlen(escval)); scsprintf(&_scratchstring[0],_SC(" %s=\"%s\""),name,escval); SendChunk(&_scratchstring[0]); }
int CSocket::Send(const void* lpBuf, int nBufLen, int nFlags) { if (m_pbBlocking != NULL) { WSASetLastError(WSAEINPROGRESS); return FALSE; } int nLeft, nWritten; PBYTE pBuf = (PBYTE)lpBuf; nLeft = nBufLen; while (nLeft > 0) { nWritten = SendChunk(pBuf, nLeft, nFlags); if (nWritten == SOCKET_ERROR) return nWritten; nLeft -= nWritten; pBuf += nWritten; } return nBufLen - nLeft; }
void SQDbgServer::EndDocument() { SendChunk(_SC("\r\n")); }
void SQDbgServer::BeginDocument() { _xmlcurrentement = -1; SendChunk(_SC("<?xml version='1.0' encoding='utf-8'?>")); }