Exemplo n.º 1
0
static void KprWebSocketHandleError(KprWebSocketEndpoint self, FskErr err, UInt16 code, char *reason)
{
	switch (err) {
		case kFskErrConnectionClosed:
			code = 1001;
			reason = "endpoint closed";
			CALLBACK(errorCallback)(self, err, reason, self->refcon);
			KprWebSocketEndpointDisconnect(self);
			return;

		case kFskErrBadData:
			code = 1002;
			reason = "protocol error";
			break;

		default:
			break;
	}

	// report error.

	if (self->state <= kKprWebSocketStateOpen) {
		CALLBACK(errorCallback)(self, err, reason, self->refcon);

		KprWebSocketEndpointClose(self, code, reason);
	}
}
Exemplo n.º 2
0
void KPR_websocketclient_close(xsMachine* the)
{
	KPR_WebSocketClientRecord *self = xsGetHostData(xsThis);
	xsIntegerValue c = xsToInteger(xsArgc);
	UInt16 code = 1000;
	char *reason = "closed by script";

	if (c >= 1) {
		code = xsToInteger(xsArg(0));
		if (code != 1000 && !(code >= 3000 && code <= 4999)) xsThrowIfFskErr(kFskErrInvalidParameter);
	}

	if (c >= 2) {
		reason = xsToString(xsArg(1));
		if (FskStrLen(reason) > 123) xsThrowIfFskErr(kFskErrInvalidParameter);
	}

	xsThrowIfFskErr(KprWebSocketEndpointClose(self->endpoint, code, reason));
}
Exemplo n.º 3
0
static FskErr KprWebSocketEndpointHandleCloseFrame(KprWebSocketEndpoint self, void *message, UInt32 length)
{
	FskErr err = kFskErrNone;
	UInt16 code;

	if (length >= sizeof(UInt16)) {
		code = *(UInt16 *)message;
		code = FskEndianU16_BtoN(code);
	} else {
		code = 1005;
	}

	self->closeWasReceived = true;
	if (self->closeWasSent) {
		KprWebSocketEndpointDisconnect(self);
	} else {
		KprWebSocketEndpointClose(self, code, "Another endpoint closed");
	}

	return err;
}