Esempio n. 1
0
void MQTTClient_writeComplete(int socket)				
{
	ListElement* found = NULL;
	
	FUNC_ENTRY;
	/* a partial write is now complete for a socket - this will be on a publish*/
	
	MQTTProtocol_checkPendingWrites();
	
	/* find the client using this socket */
	if ((found = ListFindItem(handles, &socket, clientSockCompare)) != NULL)
	{
		MQTTClients* m = (MQTTClients*)(found->content);
		
		time(&(m->c->net.lastSent));
	}
	FUNC_EXIT;
}
Esempio n. 2
0
/**
 * 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