2 * Copyright 2017 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 // This needs to be before the libevent include.
21 #include <folly/portability/Windows.h>
27 #include <event2/event_compat.h>
28 #include <folly/portability/Fcntl.h>
33 using libevent_fd_t = evutil_socket_t;
35 using libevent_fd_t = int;
38 inline libevent_fd_t getLibeventFd(int fd) {
41 return (libevent_fd_t)INVALID_HANDLE_VALUE;
43 return _get_osfhandle(fd);
49 inline int libeventFdToFd(libevent_fd_t fd) {
51 if (fd == (libevent_fd_t)INVALID_HANDLE_VALUE) {
54 return _open_osfhandle((intptr_t)fd, O_RDWR | O_BINARY);
60 using EventSetCallback = void (*)(libevent_fd_t, short, void*);
62 folly_event_set(event* e, int fd, short s, EventSetCallback f, void* arg) {
63 auto lfd = getLibeventFd(fd);
64 event_set(e, lfd, s, f, arg);