我有一个适用于 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 绑定:地址已在使用(48)”配置文件没有改变。那么为什么端口仍然与先前的线程绑定?