在ios上重启stunnel后绑定错误

时间:2013-11-05 18:14:21

标签: ios pthreads stunnel

我有一个针对iOS的stunnel构建,它运行良好,但当我尝试重新启动它时,应用程序崩溃。

我是用pthread_create开始的。 这是重启的代码。

int ret;
ret = pthread_cancel(old_threadID);
if (ret != 0)
    NSLog(@"%i", ret);

void *res;
ret = pthread_join(old_threadID, &res);
if (ret != 0)
    NSLog(@"%i", ret);

if (res == PTHREAD_CANCELED)
    NSLog(@"main(): thread was canceled\n"); //This returns OK
else
    NSLog(@"main(): thread wasn't canceled (shouldn't happen!)\n");

//Begin new thread
pthread_t threadID;
//launch stunnel in a thread
int errorStunnel = pthread_create(&threadID, NULL, &stunnel_routine, (void *)fname);
NSLog(@"Error code!! : %i", errorStunnel); //error is 0.

此应用程序崩溃后。它崩溃是因为无法正常启动。正如我在stunnel.log中看到的那样:“错误绑定:443到127.0.0.1:12345 bind:已在使用的地址(48)“ 配置文件没有改变。那么为什么端口仍然与先前的线程捆绑在一起?

1 个答案:

答案 0 :(得分:0)

取消线程时是否关闭了套接字?套接字文件描述符由整个进程共享。如果你只是吹掉线程,套接字仍然是打开的并绑定到该端口,因为网络层不知道也不关心你运行的线程数。它只知道该进程仍然打开了fd。