Skip to content

Commit 055127c

Browse files
committed
Attempting to fix nmux crash (ha7ilm#40)
1 parent eabc2c5 commit 055127c

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ nmux
33
ddcd
44
*.o
55
*.so
6+
*.so.*
67
tags
78
dumpvect.*.vect
89
*.swp

nmux.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ int main(int argc, char* argv[])
192192
if(NMUX_DEBUG)
193193
{
194194
fprintf(stderr, "\x1b[1m\x1b[33mmainfor: clients before closing: ");
195-
for(int i=0;i<clients.size();i++) fprintf(stderr, "0x%x ", (intptr_t)clients[i]);
195+
for(int i=0;i<clients.size();i++) fprintf(stderr, "%p ", clients[i]);
196196
fprintf(stderr, "\x1b[0m\n");
197197
}
198198
if(NMUX_DEBUG) fprintf(stderr, "mainfor: accepted (socket = %d).\n", new_socket);
@@ -211,7 +211,7 @@ int main(int argc, char* argv[])
211211
if(NMUX_DEBUG)
212212
{
213213
fprintf(stderr, "\x1b[1m\x1b[33mmainfor: clients after closing: ");
214-
for(int i=0;i<clients.size();i++) fprintf(stderr, "0x%x ", (intptr_t)clients[i]);
214+
for(int i=0;i<clients.size();i++) fprintf(stderr, "%p ", clients[i]);
215215
fprintf(stderr, "\x1b[0m\n");
216216
}
217217

@@ -227,7 +227,7 @@ int main(int argc, char* argv[])
227227
if(pthread_create(&new_client->thread, NULL, client_thread, (void*)new_client)==0)
228228
{
229229
clients.push_back(new_client);
230-
fprintf(stderr, MSG_START "pthread_create() done, clients now: %d\n", clients.size());
230+
fprintf(stderr, MSG_START "pthread_create() done, clients now: %d\n", (int)clients.size());
231231
}
232232
else
233233
{
@@ -278,14 +278,14 @@ int main(int argc, char* argv[])
278278

279279
void* client_thread (void* param)
280280
{
281-
fprintf(stderr, "client 0x%x: started!\n", (intptr_t)param);
281+
fprintf(stderr, "client %p: started!\n", param);
282282
client_t* this_client = (client_t*)param;
283283
this_client->status = CS_THREAD_RUNNING;
284284
int retval;
285285
tsmpool* lpool = this_client->lpool;
286-
if(NMUX_DEBUG) fprintf(stderr, "client 0x%x: socket = %d!\n", (intptr_t)param, this_client->socket);
286+
if(NMUX_DEBUG) fprintf(stderr, "client %p: socket = %d!\n", param, this_client->socket);
287287

288-
if(NMUX_DEBUG) fprintf(stderr, "client 0x%x: poll init...", (intptr_t)param);
288+
if(NMUX_DEBUG) fprintf(stderr, "client %p: poll init...", param);
289289
struct pollfd pollfds[1];
290290
pollfds[0].fd = this_client->socket;
291291
pollfds[0].events = POLLOUT;
@@ -307,25 +307,25 @@ void* client_thread (void* param)
307307
// (Wait for the server process to wake me up.)
308308
while(!pool_read_buffer || client_buffer_index >= lpool->size)
309309
{
310-
if(NMUX_DEBUG) fprintf(stderr, "client 0x%x: trying to grb\n", (intptr_t)param);
310+
if(NMUX_DEBUG) fprintf(stderr, "client %p: trying to grb\n", param);
311311
pool_read_buffer = (char*)lpool->get_read_buffer(this_client->tsmthread);
312312
if(pool_read_buffer) { client_buffer_index = 0; break; }
313-
if(NMUX_DEBUG) fprintf(stderr, "client 0x%x: cond_waiting for more data\n", (intptr_t)param);
313+
if(NMUX_DEBUG) fprintf(stderr, "client %p: cond_waiting for more data\n", param);
314314
pthread_mutex_lock(&wait_mutex);
315315
this_client->sleeping = 1;
316316
pthread_cond_wait(&wait_condition, &wait_mutex);
317317
pthread_mutex_unlock(&wait_mutex);
318318
}
319319

320320
//Wait for the socket to be available for write.
321-
if(NMUX_DEBUG) fprintf(stderr, "client 0x%x: polling for socket write...", (intptr_t)param);
321+
if(NMUX_DEBUG) fprintf(stderr, "client %p: polling for socket write...", param);
322322
int ret = poll(pollfds, 1, -1);
323323
if(NMUX_DEBUG) fprintf(stderr, "client polled for socket write.\n");
324324
if(ret == 0) continue;
325325
else if (ret == -1) { client_goto_source = 1; goto client_thread_exit; }
326326

327327
//Read data from global tsmpool and write it to client socket
328-
if(NMUX_DEBUG) fprintf(stderr, "client 0x%x: sending...", (intptr_t)param);
328+
if(NMUX_DEBUG) fprintf(stderr, "client %p: sending...", param);
329329
ret = send(this_client->socket, pool_read_buffer + client_buffer_index, lpool->size - client_buffer_index, MSG_NOSIGNAL);
330330
if(NMUX_DEBUG) fprintf(stderr, "client sent.\n");
331331
if(ret == -1)
@@ -340,7 +340,7 @@ void* client_thread (void* param)
340340
}
341341

342342
client_thread_exit:
343-
fprintf(stderr, "client 0x%x: CS_THREAD_FINISHED, client_goto_source = %d, errno = %d", (intptr_t)param, client_goto_source, errno);
343+
fprintf(stderr, "client %p: CS_THREAD_FINISHED, client_goto_source = %d, errno = %d", param, client_goto_source, errno);
344344
this_client->status = CS_THREAD_FINISHED;
345345
pthread_exit(NULL);
346346
return NULL;

tsmpool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ tsmthread_t* tsmpool::register_thread()
4242
return thread;
4343
}
4444

45-
int tsmpool::remove_thread(tsmthread_t* thread)
45+
void tsmpool::remove_thread(tsmthread_t* thread)
4646
{
4747
pthread_mutex_lock(&this->mutex);
4848
for(int i=0;i<threads.size();i++)

tsmpool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class tsmpool
3636
tsmpool(size_t size, int num);
3737
void* get_write_buffer();
3838
tsmthread_t* register_thread();
39-
int remove_thread(tsmthread_t* thread);
39+
void remove_thread(tsmthread_t* thread);
4040
void* get_read_buffer(tsmthread_t* thread);
4141
int index_next(int index) { return (index+1==num)?0:index+1; }
4242
int index_before(int index) { return (index-1<0)?num-1:index-1; }

0 commit comments

Comments
 (0)