1 // ------------------------------------------------
6 // WSys derives from Sys to provide basic win32 functions such as starting threads.
8 // (c) 2002 peercast.org
9 // ------------------------------------------------
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 // ------------------------------------------------
28 #include "..\common\stats.h"
29 #include "..\common\peercast.h"
30 #include <sys/timeb.h>
34 #include "chkMemoryLeak.h"
35 #define DEBUG_NEW new(__FILE__, __LINE__)
39 // ---------------------------------
44 rndGen.setSeed(getTime());
47 WSAClientSocket::init();
51 // ---------------------------------
52 double WSys::getDTime()
54 struct _timeb timebuffer;
56 _ftime( &timebuffer );
58 return (double)timebuffer.time+(((double)timebuffer.millitm)/1000);
60 // ---------------------------------
61 unsigned int WSys::getTime()
65 return (unsigned)ltime;
68 // ---------------------------------
69 ClientSocket *WSys::createSocket()
71 return new WSAClientSocket();
73 // ---------------------------------
74 void WSys::endThread(ThreadInfo *info)
77 // ---------------------------------
78 void WSys::waitThread(ThreadInfo *info, int timeout)
80 switch(WaitForSingleObject((void *)info->handle, timeout))
83 throw TimeoutException();
89 // ---------------------------------
90 bool WSys::startThread(ThreadInfo *info)
94 /* typedef unsigned ( __stdcall *start_address )( void * );
96 unsigned int threadID;
97 info->handle = (unsigned int)_beginthreadex( NULL, 0, (start_address)info->func, info, 0, &threadID );
102 typedef void (__cdecl *start_address)( void * );
103 info->handle = _beginthread((start_address)info->func, 0,info);
105 if(info->handle == -1)
111 // ---------------------------------
112 void WSys::sleep(int ms)
117 // ---------------------------------
118 void WSys::appMsg(long msg, long arg)
120 //SendMessage(mainWindow,WM_USER,(WPARAM)msg,(LPARAM)arg);
123 // --------------------------------------------------
124 void WSys::callLocalURL(const char *str,int port)
127 sprintf(cmd,"http://127.0.0.1:%d/%s",port,str);
128 ShellExecute(mainWindow, NULL, cmd, NULL, NULL, SW_SHOWNORMAL);
131 // ---------------------------------
132 void WSys::getURL(const char *url)
135 if (strnicmp(url,"http://",7) || strnicmp(url,"mailto:",7))
136 ShellExecute(mainWindow, NULL, url, NULL, NULL, SW_SHOWNORMAL);
138 // ---------------------------------
142 PostMessage(mainWindow,WM_CLOSE,0,0);
146 // --------------------------------------------------
147 void WSys::executeFile(const char *file)
149 ShellExecute(NULL,"open",file,NULL,NULL,SW_SHOWNORMAL);