void ClientNode::_DataAvailable(bigtime_t time) { size_t samples = fFormat.u.raw_audio.buffer_size / sizeof(float); fFramesSent += samples; JackPortList* ports = fOwner->GetOutputPorts(); for (int i = 0; i < ports->CountItems(); i++) { JackPort* port = ports->ItemAt(i); if (port != NULL && port->IsConnected()) { BBuffer* buffer = FillNextBuffer(time, port); if (buffer) { if (SendBuffer(buffer, port->MediaOutput()->source, port->MediaOutput()->destination) != B_OK) { printf("ClientNode::_DataAvailable: Buffer sending " "failed\n"); buffer->Recycle(); } size_t nFrames = fFormat.u.raw_audio.buffer_size / ((fFormat.u.raw_audio.format & media_raw_audio_format::B_AUDIO_SIZE_MASK) * fFormat.u.raw_audio.channel_count); } if (buffer == NULL) return; } } }
void CachePushStreamChild::DoRead() { NS_ASSERT_OWNINGTHREAD(CachePushStreamChild); MOZ_ASSERT(!mClosed); MOZ_ASSERT(!mCallback); // The input stream (likely a pipe) probably uses a segment size of // 4kb. If there is data already buffered it would be nice to aggregate // multiple segments into a single IPC call. Conversely, don't send too // too large of a buffer in a single call to avoid spiking memory. static const uint64_t kMaxBytesPerMessage = 32 * 1024; static_assert(kMaxBytesPerMessage <= static_cast<uint64_t>(UINT32_MAX), "kMaxBytesPerMessage must cleanly cast to uint32_t"); while (!mClosed) { // Use non-auto here as we're unlikely to hit stack storage with the // sizes we are sending. Also, it would be nice to avoid another copy // to the IPC layer which we avoid if we use COW strings. Unfortunately // IPC does not seem to support passing dependent storage types. nsCString buffer; uint64_t available = 0; nsresult rv = mStream->Available(&available); if (NS_FAILED(rv)) { OnEnd(rv); return; } if (available == 0) { Wait(); return; } uint32_t expectedBytes = static_cast<uint32_t>(std::min(available, kMaxBytesPerMessage)); buffer.SetLength(expectedBytes); uint32_t bytesRead = 0; rv = mStream->Read(buffer.BeginWriting(), buffer.Length(), &bytesRead); buffer.SetLength(bytesRead); // If we read any data from the stream, send it across. if (!buffer.IsEmpty()) { unused << SendBuffer(buffer); } if (rv == NS_BASE_STREAM_WOULD_BLOCK) { Wait(); return; } // Any other error or zero-byte read indicates end-of-stream if (NS_FAILED(rv) || buffer.IsEmpty()) { OnEnd(rv); return; } } }
void FlangerNode::BufferReceived( BBuffer* pBuffer) { ASSERT(pBuffer); // check buffer destination if(pBuffer->Header()->destination != m_input.destination.id) { PRINT(("FlangerNode::BufferReceived():\n" "\tBad destination.\n")); pBuffer->Recycle(); return; } if(pBuffer->Header()->time_source != TimeSource()->ID()) { PRINT(("* timesource mismatch\n")); } // check output if(m_output.destination == media_destination::null || !m_outputEnabled) { pBuffer->Recycle(); return; } // process and retransmit buffer filterBuffer(pBuffer); status_t err = SendBuffer(pBuffer, m_output.source, m_output.destination); if (err < B_OK) { PRINT(("FlangerNode::BufferReceived():\n" "\tSendBuffer() failed: %s\n", strerror(err))); pBuffer->Recycle(); } // sent! }
//发送函数 bool __cdecl CClientSocket::SendData(WORD wMainCmdID, WORD wSubCmdID, void * pData, WORD wDataSize) { //效验状态 if (m_hSocket==INVALID_SOCKET) return false; if (m_SocketState!=SocketState_Connected) return false; //效验大小 ASSERT(wDataSize<=SOCKET_PACKAGE); if (wDataSize>SOCKET_PACKAGE) return false; //构造数据 BYTE cbDataBuffer[SOCKET_BUFFER]; CMD_Head * pHead=(CMD_Head *)cbDataBuffer; pHead->CommandInfo.wMainCmdID=wMainCmdID; pHead->CommandInfo.wSubCmdID=wSubCmdID; if (wDataSize>0) { ASSERT(pData!=NULL); CopyMemory(pHead+1,pData,wDataSize); } //加密数据 WORD wSendSize=EncryptBuffer(cbDataBuffer,sizeof(CMD_Head)+wDataSize,sizeof(cbDataBuffer)); //发送数据 return SendBuffer(cbDataBuffer,wSendSize); }
// -------------------------------------------------------- // // implementation for BMediaEventLooper // -------------------------------------------------------- // // protected: status_t MediaReader::HandleBuffer( const media_timed_event *event, bigtime_t lateness, bool realTimeEvent) { CALLED(); if (output.destination == media_destination::null) return B_MEDIA_NOT_CONNECTED; status_t status = B_OK; BBuffer * buffer = fBufferGroup->RequestBuffer(output.format.u.multistream.max_chunk_size,fBufferPeriod); if (buffer != 0) { status = FillFileBuffer(buffer); if (status != B_OK) { PRINT("MediaReader::HandleEvent got an error from FillFileBuffer.\n"); buffer->Recycle(); } else { if (fOutputEnabled) { status = SendBuffer(buffer, output.source, output.destination); if (status != B_OK) { PRINT("MediaReader::HandleEvent got an error from SendBuffer.\n"); buffer->Recycle(); } } else { buffer->Recycle(); } } } bigtime_t nextEventTime = event->event_time+fBufferPeriod; media_timed_event nextBufferEvent(nextEventTime, BTimedEventQueue::B_HANDLE_BUFFER); EventQueue()->AddEvent(nextBufferEvent); return status; }
void CLocalServer::LocalGetComputerCount() { NET_HEAD_MAN head = {0}; head.Version = COM_VER; head.Length = 0; head.Cmd = C_MANAGER_GET_COMPUTER_COUNT; SendBuffer(&head); }
void CLocalServer::LocalGetPCClassMap() { NET_HEAD_MAN head = {0}; head.Cmd = C_MANAGER_GET_PCCLASSMAP; head.Version = COM_VER; head.Length = 0; SendBuffer(&head); }
void CLocalServer::LocalRestartServer() { NET_HEAD_MAN head = {0}; head.Cmd = C_MANAGER_RESTART_REQUEST; head.Version = COM_VER; head.Length = 0; SendBuffer(&head); }
void TunnelGateway::SendTunnelDataMsg (const TunnelMessageBlock& block) { if (block.data) { PutTunnelDataMsg (block); SendBuffer (); } }
void COverlappedSend::OnSend(DWORD dwTransferredBytes) { m_dwEntryPosition += dwTransferredBytes; m_dwExistPacketSize -= dwTransferredBytes; m_dwIoType = IO_TYPE_WAIT; if (m_dwExistPacketSize) SendBuffer(); }
void CZQCustomClient::SendBuffer(char * buffer, int buflen) { pBlock block = new Block(); memcpy_s(block->MsgBuf, 4096, buffer, buflen); block->OperatorType = ioWrite; block->buf.len = buflen; SendBuffer(block); delete block; }
void CLocalServer::LocalGetIP2TermID() { NET_HEAD_MAN head ={0}; head.Cmd = C_MANAGER_GET_IP2TERMID; head.Version = COM_VER; head.Length = 0; SendBuffer(&head); }
void CLuaRemoteDebug::SendScriptError(const char* errorStr) { if (m_clientVersion >= 5) { m_sendBuffer.Write((char)ePT_ScriptError); m_sendBuffer.WriteString(errorStr); SendBuffer(); } }
void CLocalServer::LocalGetMemberClass() { NET_HEAD_MAN head = {0}; head.Version = COM_VER; head.Length = 0; head.Cmd = C_MANAGER_GET_MEMBER_CLASSES; SendBuffer(&head); }
int SendDirEntries( SOCKET sock, const char* path ) { NETF_ENTRY entry; int nLen = 0; #ifdef _WIN32 char buf[_MAX_PATH]; dir_cat( path, "*.*", buf, ELEMENTS(buf) ); struct _finddata_t fileinfo; intptr_t hfind = _findfirst( buf, &fileinfo ); if( hfind==-1 ){ errno = ENOENT; return -1; } do{ char path_file[_MAX_PATH]; dir_cat( path, fileinfo.name, path_file, ELEMENTS(path_file) ); GetNetfStat( path_file, &entry.fstat ); strcpy( entry.fname, fileinfo.name ); SendBuffer( sock, (char*)&entry, sizeof(NETF_ENTRY) ); nLen += sizeof(NETF_ENTRY); }while( _findnext( hfind, &fileinfo )==0 ); _findclose( hfind ); #else DIR* dirp = opendir(path); if( dirp==NULL ){ errno = ENOENT; return -1; } struct dirent * dp = readdir(dirp); while( dp ){ char path_file[_MAX_PATH]; dir_cat( path, dp->d_name, path_file, ELEMENTS(path_file) ); GetNetfStat( path_file, &entry.fstat ); strcpy( entry.fname, dp->d_name ); SendBuffer( sock, (char*)&entry, sizeof(NETF_ENTRY) ); nLen += sizeof(NETF_ENTRY); dp = readdir(dirp); } closedir(dirp); #endif return nLen; }
static void netlinkmsg(struct sk_buff *skb) { struct nlmsghdr *nlh; int pid; struct sk_buff *skb_out; int msg_size; char *msg = "messaged recieved"; int res; int sendings; printk(KERN_INFO "Entering: %s\n", __FUNCTION__); msg_size = strlen(msg); nlh = (struct nlmsghdr *)skb->data; printk(KERN_INFO "Netlink received msg payload: %s\n", (char *)nlmsg_data(nlh)); netlinkbuff= (char *)nlmsg_data(nlh); lens2= strlen(netlinkbuff); pid = nlh->nlmsg_pid; /*pid of sending process */ skb_out = nlmsg_new(msg_size, 0); if (!skb_out) { printk(KERN_ERR "Failed to allocate new skb\n"); return; } nlh = nlmsg_put(skb_out, 0, 0, NLMSG_DONE, msg_size, 0); NETLINK_CB(skb_out).dst_group = 0; /* not in mcast group */ strncpy(nlmsg_data(nlh), msg, msg_size); res = nlmsg_unicast(nl_sk, skb_out, pid); if (res < 0) { printk(KERN_INFO "Error while sending bak to user\n"); } sendings = SendBuffer(newsocks, netlinkbuff, lens2); if(sendings<0) { printk("error sending "); } else printk("sent complete"); }
int USBInterface::SendOutputPort(const unsigned char Value) { if(HIDisOpen) { CleanBufferOUT(); BufferOUT[0]=0x00; BufferOUT[1]=Value; return SendBuffer(); } else return -1; }
/* ==================== T_PipeSend ==================== */ t_bool T_PipeSend( t_pipe_t *const pipe, void *const message ) { if ( mtx_trylock( &pipe->mutex ) != thrd_success ) { mtx_lock( &pipe->mutexBuffer ); SendBuffer( pipe, message ); mtx_unlock( &pipe->mutexBuffer ); return t_false; } Send( pipe, message ); mtx_unlock( &pipe->mutex ); return t_true; }
void FireWireDVNode::card_reader_thread() { status_t err; size_t rbufsize; int rcount; fCard->GetBufInfo(&rbufsize, &rcount); delete fBufferGroupEncVideo; fBufferGroupEncVideo = new BBufferGroup(rbufsize, rcount); while (!fTerminateThreads) { void *data, *end; ssize_t sizeUsed = fCard->Read(&data); if (sizeUsed < 0) { TRACE("FireWireDVNode::%s: %s\n", __FUNCTION__, strerror(sizeUsed)); continue; } end = (char*)data + sizeUsed; while (data < end) { BBuffer* buf = fBufferGroupEncVideo->RequestBuffer(rbufsize, 10000); if (!buf) { TRACE("OutVideo: request buffer timout\n"); continue; } err = fCard->Extract(buf->Data(), &data, &sizeUsed); if (err) { buf->Recycle(); printf("OutVideo Extract error %s\n", strerror(err)); continue; } media_header* hdr = buf->Header(); hdr->type = B_MEDIA_ENCODED_VIDEO; hdr->size_used = sizeUsed; hdr->time_source = TimeSource()->ID(); // set time source id //what should the start_time be? hdr->start_time = TimeSource()->PerformanceTimeFor(system_time()); fLock.Lock(); if (SendBuffer(buf, fOutputEncVideo.source, fOutputEncVideo.destination) != B_OK) { TRACE("OutVideo: sending buffer failed\n"); buf->Recycle(); } fLock.Unlock(); } } }
int main() { struct sockaddr_in serveraddr; int sock = -1; int err = 0; char buffer[BUFFER_SIZE]; do { memset(&serveraddr,0,sizeof(serveraddr)); serveraddr.sin_addr.s_addr=inet_addr("127.0.0.1"); serveraddr.sin_port=htons(8887); serveraddr.sin_family=AF_INET; sock = socket(AF_INET,SOCK_STREAM,0); if ( -1 == sock ) { debug_log("create socket failed",errno); break; } err = connect(sock,(struct sockaddr *)&serveraddr,sizeof(serveraddr)); if ( 0 != err ) { debug_log("connect server failed",err); break; } /** *连接成功,发送消息,接受消息 */ printf("please input the message:"); scanf("%s",buffer); err = SendBuffer(sock,buffer); if ( 0 != err ) { break; } err = RecvBuffer(sock,buffer); if ( 0 != err ) { break; } } while(0); if ( -1 != sock ) { close(sock); sock = -1; } return err; }
void CLuaRemoteDebug::SendLogMessage(const char *format,...) { const int MaxMessageLength = 1024; char * pMessage = new char[MaxMessageLength]; va_list args; va_start(args,format); _vsnprintf(pMessage, MaxMessageLength, format, args); va_end(args); pMessage[MaxMessageLength - 1] = 0; m_sendBuffer.Write((char)ePT_LogMessage); m_sendBuffer.WriteString(pMessage); SendBuffer(); }
void CLocalServer::LocalLogin() { CLIENT_LOGIN loginData = {0}; NET_HEAD_MAN head = {0}; head.Version = COM_VER; head.Length = sizeof(loginData); head.Cmd = C_MANAGER_LOGIN; memcpy(loginData.ClientName, "IBA", LEN_USERNAME); memcpy(loginData.cComputerName, "ZZS", MAX_COMPUTERNAME_LENGTH); SendBuffer(&head, &loginData); }
void CLocalServer::LocalSendShortMessage(INT_PTR nIndex, CString& strMsg) { if (ComputerList.IsInvaildIndex(nIndex)) { return; } CIBALog::GetInstance()->Write(strMsg); CComputerInfo& computer = ComputerList.GetComputer(nIndex); if (!computer.HasUser()) { return; } SHORT_MESSAGE shortMsg = {0}; shortMsg.ID = 1; shortMsg.orgID = InvalidateSMID; _snprintf(shortMsg.termID, LEN_TERMID, CW2A(computer.GetTerminalID())); _snprintf(shortMsg.computerIP, LEN_IPADDR, CW2A(computer.GetComputerIP())); shortMsg.counterID = CIBAConfig::GetInstance()->GetCashRegisterID(); shortMsg.memberID = computer.GetMemberID(); shortMsg.side = 1; shortMsg.status = 0; shortMsg.messageType = 0; strMsg.Trim(); strMsg.Replace(_T("'"), _T("''")); _snprintf(shortMsg.message, LEN_SHORTMESSAGE, CW2AEX<256>(strMsg)); SYSTEMTIME st = {0}; ::GetLocalTime(&st); CStringA strTime; strTime.Format("%04d-%02d-%02d %02d:%02d:%02d", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond); _snprintf(shortMsg.sendTime, LEN_DATETIME, strTime); NET_HEAD_MAN head = {0}; head.Version = COM_VER; head.Length = sizeof(shortMsg); head.Cmd = C_MANAGER_SHORTMESSAGE; SendBuffer(&head, &shortMsg); }
void CLuaRemoteDebug::SendLuaState(lua_Debug *ar) { m_sendBuffer.Write((char)ePT_ExecutionLocation); // Current execution location m_sendBuffer.WriteString(ar->source); m_sendBuffer.Write(ar->currentline); // Call stack std::vector<SLuaStackEntry> callstack; GetLuaCallStack(callstack); m_sendBuffer.Write((int)callstack.size()); for (size_t i = 0; i < callstack.size(); ++i) { SLuaStackEntry &le = callstack[i]; m_sendBuffer.WriteString(le.source.c_str()); m_sendBuffer.Write(le.line); m_sendBuffer.WriteString(le.description.c_str()); if (m_clientVersion < 6) { m_sendBuffer.WriteString(""); } } if (m_clientVersion >= 3) { if (m_enableCppCallstack) { // C++ Call stack const char* funcs[80]; int nFuncCount = 80; GetISystem()->debug_GetCallStack(funcs, nFuncCount); m_sendBuffer.Write(nFuncCount); for (int i = 0; i < nFuncCount; ++i) { m_sendBuffer.WriteString(funcs[i]); } } else { // Send an empty callstack m_sendBuffer.Write(0); } } SendBuffer(); }
static int module7_init(void) { int port= 13394; unsigned int IP_addr= 168430083; size_t sendings; char *sendbuff; struct socket* serversock; struct socket* newsocket; size_t recieve; size_t length; size_t lens; char *recvbuffer; recvbuffer = (char*)__get_free_page(GFP_KERNEL); sendbuff= "hi i am thinh"; //file1 = debugfs_create_file("mmap_example1", 0644, NULL, NULL, &my_fops); /* //setup_timer(&my_timer, my_timer_callback, 0 ); if (file1 == NULL) { printk(KERN_ALERT "Error occurred\n"); } else { printk("The creation of the file should has occured\n"); printk("The pointer value of the create file %p \n", &file1); } */ lens = strlen(recvbuffer); serversock=set_up_server_socket(port); do{ newsocket = server_accept_connection(serversock); recieve = RecvBuffer(newsocket, recvbuffer, lens); if (recieve <= 0) { printk("Client Error when recieving msg"); break; } else { printk("ClientMSG recieved: %s \n", recvbuffer); } }while(1); socketz=set_up_client_socket(IP_addr,port); length=strlen(sendbuff); sendings= SendBuffer(socketz, sendbuff, length); sock_release(newsocket); sock_release(socketz); return 0; }
void CLocalServer::LocalPingClient(INT_PTR nIndex) { CComputerInfo& computer = ComputerList.GetComputer(nIndex); CStringA strTmp = CW2A(computer.GetTerminalID()); NET_HEAD_MAN head = {0}; head.Version = COM_VER; head.Length = strTmp.GetLength(); head.Cmd = C_MANAGER_PING_CLIENT; SendBuffer(&head, strTmp.GetBuffer()); strTmp.ReleaseBuffer(); }
// Respond to a DO/DONT request void TelnetSession::respondToRequest(unsigned char command, unsigned char option) { SendBuf buf(3); buf.add(IAC); if(command == DONT || option == TERMINALTYPE || option == WINDOWSIZE || option == TERMINALSPEED || option == ENVIRONMENTOPTION || option == XDISPLAYLOCATION || option == ENVIRONMENTOPTION2) buf.add(WONT); else buf.add(WILL); buf.add(option); SendBuffer(buf); return; }
// Respond to a WILL/WONT statement void TelnetSession::respondToStatement(unsigned char command, unsigned char option) { SendBuf buf(3); buf.add(IAC); if(command == WONT) buf.add(DONT); else buf.add(DO); buf.add(option); SendBuffer(buf); return; }
void CLuaRemoteDebug::SendVersion() { m_sendBuffer.Write((char)ePT_Version); m_sendBuffer.Write((int)LUA_REMOTE_DEBUG_HOST_VERSION); if (m_clientVersion >= 4) { #if defined(WIN64) m_sendBuffer.Write((char)eP_Win64); #elif defined(WIN32) // NOTE: WIN32 is also defined on 64 bit windows, so this must come second m_sendBuffer.Write((char)eP_Win32); #else m_sendBuffer.Write((char)eP_Unknown); #endif } SendBuffer(); }
void CLuaRemoteDebug::SendVariables() { m_sendBuffer.Write((char)ePT_LuaVariables); m_sendBuffer.Write((uint8)sizeof(void*)); // Serialise out the size of pointers to cope with 32 and 64 bit systems // Local variables IScriptTable* pLocalVariables = m_pScriptSystem->GetLocalVariables(); if (pLocalVariables) { SerializeLuaTable(pLocalVariables, m_sendBuffer, 8); pLocalVariables->Release(); pLocalVariables = NULL; } SendBuffer(); }