00001 /* Copyright 2010 Jukka Jylänki 00002 00003 Licensed under the Apache License, Version 2.0 (the "License"); 00004 you may not use this file except in compliance with the License. 00005 You may obtain a copy of the License at 00006 00007 http://www.apache.org/licenses/LICENSE-2.0 00008 00009 Unless required by applicable law or agreed to in writing, software 00010 distributed under the License is distributed on an "AS IS" BASIS, 00011 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00012 See the License for the specific language governing permissions and 00013 limitations under the License. */ 00014 #pragma once 00015 00019 #ifdef WIN32 00020 #include "win32/WS2Include.h" 00021 #endif 00022 00023 namespace kNet 00024 { 00025 00026 enum EventWaitType 00027 { 00028 EventWaitDummy, 00029 EventWaitSignal, 00030 EventWaitRead, 00031 EventWaitWrite 00032 }; 00033 00035 00054 class Event 00055 { 00056 public: 00058 Event(); 00059 // Does not delete the event. Call Event::Close() when you don't need it anymore. 00060 // ~Event(); 00061 00064 void Create(EventWaitType type); 00065 00067 void Close(); 00068 00070 bool IsNull() const; 00071 00073 bool IsValid() const; 00074 00076 void Reset(); 00077 00079 void Set(); 00080 00082 bool Test() const; 00083 00086 bool Wait(unsigned long msecs) const; 00087 00089 EventWaitType Type() const { return type; } 00090 00091 private: 00092 EventWaitType type; 00093 00094 #ifdef WIN32 00095 public: 00096 WSAEVENT wsaEvent; 00097 00099 explicit Event(WSAEVENT wsaEvent, EventWaitType eventType); 00100 #elif LINUX 00101 public: 00102 int fd; 00103 00105 explicit Event(int /*SOCKET*/ fd, EventWaitType eventType); 00106 00107 #endif 00108 }; 00109 00111 Event CreateNewEvent(EventWaitType type); 00112 00113 } // ~kNet
1.7.1