コード例 #1
0
ファイル: MQTTProtocol.c プロジェクト: Frank-KunLi/DTLS_RSMB
/**
 * Initialize the MQTT protocol modules.
 * @param aBrokerState pointer to the broker state structure
 */
int MQTTProtocol_initialize(BrokerStates* aBrokerState)
{
	int rc = 0;
	FUNC_ENTRY;

	bstate = aBrokerState;
	memset(&state, '\0', sizeof(state));
	rc = MQTTProtocol_reinitialize();
	FUNC_EXIT_RC(rc);
	return rc;
}
コード例 #2
0
ファイル: Protocol.c プロジェクト: TeamElevate/edison
/**
 * Timeslice function to run protocol exchanges
 */
void Protocol_timeslice()
{
	int sock;
	int bridge_connection = 0;
	static int more_work = 0;

	FUNC_ENTRY;
	if ((sock = Socket_getReadySocket(more_work, NULL)) == SOCKET_ERROR)
	{
#if defined(WIN32)
		int errno;
		errno = WSAGetLastError();
#endif
		if (errno != EINTR && errno != EAGAIN && errno != EINPROGRESS && errno != EWOULDBLOCK)
		{
			Log(LOG_SEVERE, 0, "Restarting MQTT protocol to resolve socket problems");
			MQTTProtocol_shutdown(0);
			SubscriptionEngines_save(bstate->se);
			MQTTProtocol_reinitialize();
			goto exit;
		}
	}

	MQTTProtocol_checkPendingWrites();
	if (sock > 0)
	{
		Clients* client = NULL;
		Node* curnode = TreeFind(bstate->clients, &sock);

		if (curnode)
		{
			client = (Clients*)(curnode->content);
#if !defined(NO_BRIDGE)
			if (client->outbound && client->connect_state == 1)
			{
				Bridge_handleConnection(client);
				bridge_connection = 1;
			}
#endif
		}
		
		if (bridge_connection == 0)
#if defined(MQTTS)
		{
			int protocol = PROTOCOL_MQTT;
			if (client == NULL)
				protocol = Socket_getParentListener(sock)->protocol;
			else
				protocol = client->protocol;

			if (protocol == PROTOCOL_MQTT)
#endif
				MQTTProtocol_timeslice(sock, client);
#if defined(MQTTS)
			else if (protocol == PROTOCOL_MQTTS)
			    MQTTSProtocol_timeslice(sock);
		}
#endif
	}
	if (bstate->state != BROKER_STOPPING)
#if !defined(NO_ADMIN_COMMANDS)
		Persistence_read_command(bstate);
#else
		;
#endif
	else