Sese Framework  2.3.0
A cross-platform framework
Loading...
Searching...
No Matches
WSAEventLoop.h
Go to the documentation of this file.
1// Copyright 2024 libsese
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
21#pragma once
22
26
27#include <atomic>
28
29#define MAX_EVENT_SIZE 64
30
31namespace sese::event {
34public:
35 ~WSAEventLoop() override;
36
37 bool init() override;
38
39 void dispatch(uint32_t timeout) override;
40
41 void onAccept(int fd) override;
42
43 void onRead(BaseEvent *event) override;
44
45 void onWrite(BaseEvent *event) override;
46
47 void onError(BaseEvent *event) override;
48
49 void onClose(BaseEvent *event) override;
50
51 BaseEvent *createEvent(int fd, unsigned int events, void *data) override;
52
53 void freeEvent(BaseEvent *event) override;
54
55 bool setEvent(BaseEvent *event) override;
56
57 void setListenFd(int fd) override;
58
59protected:
60 int listenFd{-1};
62
63 void *wsaEvent{nullptr};
65
66 unsigned long numbers = 0;
67 unsigned long long sockets[MAX_EVENT_SIZE]{};
69 // Here, the lifecycle should be the responsibility of the user
71};
72
73} // namespace sese::event
74
75#undef MAX_EVENT_SIZE