📄 xsys.cpp
字号:
// ------------------------------------------------// File : xsys.cpp// Date: 25-mar-2004// Author: giles// Desc: // XSys derives from Sys to provide basic darwin functions such as starting threads.//// (c) 2002-2004 peercast.org// ------------------------------------------------// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.// ------------------------------------------------#include <time.h>#include <pthread.h>#include <signal.h>#include <stdlib.h>#include "xsys.h"#include "xsocket.h"#include "stats.h"// ---------------------------------XSys::XSys(){ stats.clear(); rndGen.setSeed(rnd()+getpid()); signal(SIGPIPE, SIG_IGN); rndSeed = rnd();}// ---------------------------------unsigned int XSys::getTime(){ time_t ltime; time( <ime ); return ltime;}// ---------------------------------ClientSocket *XSys::createSocket(){ return new XClientSocket();} typedef void *(*THREAD_PTR)(void *);// ---------------------------------bool XSys::startThread(ThreadInfo *info){ info->active = true;#if 1 pthread_t thread; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);// LOG_DEBUG("Starting thread"); int r = pthread_create(&thread,&attr,(THREAD_PTR)info->func,info);// int r = pthread_create(&thread,NULL,(THREAD_PTR)info->func,info);// LOG_DEBUG("Starting thread done"); if (r) LOG_ERROR("Error creating thread: %d",r); return r==0;#endif#if 0 pthread_t mythread; if ( pthread_create( &mythread, NULL, (THREAD_PTR)info->func, info) ) { LOG_ERROR("error creating thread."); return false; } LOG_DEBUG("Thread started OK");// if ( pthread_join ( mythread, NULL ) ) // {// LOG_ERROR("error joining thread.");// return false;// } return true;#endif}// ---------------------------------void XSys::sleep(int ms){ ::usleep(ms*1000);}// ---------------------------------void XSys::appMsg(long msg, long arg){ //SendMessage(mainWindow,WM_USER,(WPARAM)msg,(LPARAM)arg);}// ---------------------------------void XSys::getURL(const char *url){}// ---------------------------------void XSys::exit(){ ::exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -