예제 #1
0
status_t
CDDBServer::_SendCommand(const BString& command, BString& output)
{
	if (!fConnected)
		return B_ERROR;

	// Assemble full command string.
	BString fullCommand;
	fullCommand << command << "&hello=" << fLocalUserName << " " <<
		fLocalHostName << " cddb_lookup 1.0&proto=6";

	// Replace spaces by + signs.
	fullCommand.ReplaceAll(" ", "+");

	// And now add command header and footer.
	fullCommand.Prepend("GET /~cddb/cddb.cgi?cmd=");
	fullCommand << " HTTP 1.0\n\n";

	int32 result = fConnection.Send((void*)fullCommand.String(),
		fullCommand.Length());
	if (result == fullCommand.Length()) {
		BNetBuffer netBuffer;
		while (fConnection.Receive(netBuffer, 1024) != 0) {
			// Do nothing. Data is automatically appended to the NetBuffer.
		}

		// AppendString automatically adds the terminating \0.
		netBuffer.AppendString("");

		output.SetTo((char*)netBuffer.Data(), netBuffer.Size());
		return B_OK;
	}

	return B_ERROR;
}
예제 #2
0
int32 WatchNetEndpoint::Receive(BNetBuffer &buffer, size_t size, int flags = 0)
{
	int32 returnVal = BNetEndpoint::Receive(buffer, size, flags);
	if(returnVal > 0)
	{
		BString recStr;
		if (buffer.Size() > 0)
		{	
			recStr.SetTo((const char*)buffer.Data(), buffer.Size());
		}
		
		BMessage recMsg('ADMS');
		recMsg.AddInt8("Type", DATA_RECEIVED_EVENT);
		recMsg.AddString("Text", recStr);
		watchWin->PostMessage(&recMsg);
	}
	return returnVal;
}
예제 #3
0
int32
BNetEndpoint::SendTo(BNetBuffer& buffer,
	const BNetAddress& address, int flags)
{
	return SendTo(buffer.Data(), buffer.Size(), address, flags);
}
예제 #4
0
int32
BNetEndpoint::Send(BNetBuffer& buffer, int flags)
{
	return Send(buffer.Data(), buffer.Size(), flags);
}
예제 #5
0
int32 WatchNetEndpoint::Send(BNetBuffer &pack, int flags)
{
	return Send(pack.Data(),pack.Size(),flags);
}