Esempio n. 1
0
FskErr KprDebugMachineNew(KprDebugMachine* it, KprDebug debug, FskSocket skt)
{
	FskErr err = kFskErrNone;
	KprDebugMachine self = NULL;
	UInt32 ip;
	int port;
	
	BAIL_IF_ERR(err = FskMemPtrNewClear(sizeof(KprDebugMachineRecord), it));
	self = *it;
	self->debug = debug;
	self->socket = skt;

	BAIL_IF_ERR(err = FskNetSocketGetRemoteAddress(skt, &ip, &port));
	FskNetIPandPortToString(ip, port, self->address);

	FskListAppend(&self->debug->machine, self);

	FskNetSocketReceiveBufferSetSize(self->socket, kSocketBufferSize);

	FskThreadAddDataHandler(&self->reader, (FskThreadDataSource)self->socket, KprDebugMachineDataReader, true, false, self);

	bailIfError(KprSocketWriterNew(&self->writer, self->socket, self));
	self->writer->errorCallback = KprDebugMachineWriteError;

	KprDebugMachineCallbackText(self, "onMachineRegistered", mxNoCommand, NULL);

	FskInstrumentedItemNew(self, NULL, &KprDebugMachineInstrumentation);
	return err;
bail:
	KprDebugMachineDispose(self);
	return err;
}
Esempio n. 2
0
static FskErr KprWebSocketEndpointSetupSocketReader(KprWebSocketEndpoint self, FskSocket skt, int initialState)
{
	FskErr err = kFskErrNone;
	KprSocketReaderState states[] = {
		{
			kKprWebSocketEndpoint_onHeader,
			(KprSocketReaderCallback) KprWebSocketEndpointReadHeader
		},
		{
			kKprWebSocketEndpoint_onFrameOpcode,
			(KprSocketReaderCallback) KprWebSocketEndpointReadFrameOpcode
		},
		{
			kKprWebSocketEndpoint_onFrameLength,
			(KprSocketReaderCallback) KprWebSocketEndpointReadFrameLength
		},
		{
			kKprWebSocketEndpoint_onFrameLength16,
			(KprSocketReaderCallback) KprWebSocketEndpointReadFrameLength16
		},
		{
			kKprWebSocketEndpoint_onFrameLength64,
			(KprSocketReaderCallback) KprWebSocketEndpointReadFrameLength64
		},
		{
			kKprWebSocketEndpoint_onFrameMaskData,
			(KprSocketReaderCallback) KprWebSocketEndpointReadFrameMaskData
		},
		{
			kKprWebSocketEndpoint_onFrameMessage,
			(KprSocketReaderCallback) KprWebSocketEndpointReadFrameMessage
		},
	};
	UInt32 stateCount = sizeof(states) / sizeof(KprSocketReaderState);
	KprSocketReader reader;
	KprSocketWriter writer;

	bailIfError(KprSocketReaderNew(&reader, skt, states, stateCount, self));
	bailIfError(KprSocketWriterNew(&writer, skt, self));

	FskNetSocketReceiveBufferSetSize(skt, kSocketBufferSize);

	reader->errorCallback = KprWebSocket_onReadError;
	KprSocketReaderSetState(reader, initialState);

	writer->errorCallback = KprWebSocket_onWriteError;

	self->socket = skt;
	self->reader = reader;
	self->writer = writer;

bail:
	if (err) {
		KprSocketReaderDispose(reader);
		KprSocketWriterDispose(writer);
	}
	return err;
}