Commits

Roger Light  committed 344120b

Break out of select() when calling mosquitto_loop_stop().

  • Participants
  • Parent commits eedb066
  • Branches 1.3.1

Comments (0)

Files changed (2)

File ChangeLog.txt

 Client library:
 - Fix socketpair code on the Mac.
 - Fix compilation for WITH_THREADING=no.
+- Break out of select() when calling mosquitto_loop_stop().
 
 Clients:
 - Fix keepalive value on mosquitto_pub.

File lib/thread_mosq.c

 /*
-Copyright (c) 2011-2013 Roger Light <roger@atchoo.org>
+Copyright (c) 2011-2014 Roger Light <roger@atchoo.org>
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
 #endif
 
 #include "mosquitto_internal.h"
+#include "net_mosq.h"
 
 void *_mosquitto_thread_main(void *obj);
 
 int mosquitto_loop_stop(struct mosquitto *mosq, bool force)
 {
 #ifdef WITH_THREADING
+#  ifndef WITH_BROKER
+	char sockpair_data = 0;
+#  endif
+
 	if(!mosq || !mosq->threaded) return MOSQ_ERR_INVAL;
+
+
+	/* Write a single byte to sockpairW (connected to sockpairR) to break out
+	 * of select() if in threaded mode. */
+	if(mosq->sockpairW != INVALID_SOCKET){
+#ifndef WIN32
+		if(write(mosq->sockpairW, &sockpair_data, 1)){
+		}
+#else
+		send(mosq->sockpairW, &sockpair_data, 1, 0);
+#endif
+	}
 	
 	if(force){
 		pthread_cancel(mosq->thread_id);