Skip to content

Commit

Permalink
Fix windows-x64 platform compile issues
Browse files Browse the repository at this point in the history
  • Loading branch information
zieckey committed May 28, 2017
1 parent 39d7e23 commit b2535d7
Show file tree
Hide file tree
Showing 33 changed files with 110 additions and 100 deletions.
4 changes: 2 additions & 2 deletions benchmark/ioevent/evpp/evpp_ioevent_bench.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

using namespace evpp;

std::vector<int> g_pipes;
std::vector<evpp_socket_t> g_pipes;
int numPipes;
int numActive;
int numWrites;
Expand All @@ -30,7 +30,7 @@ std::vector<FdChannel*> g_channels;
int g_reads, g_writes, g_fired;
int g_total_reads = 0;

void readCallback(int fd, int idx) {
void readCallback(evpp_socket_t fd, int idx) {
g_total_reads++;
char ch = 0;
g_reads += static_cast<int>(::recv(fd, &ch, sizeof(ch), 0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

using namespace evpp;

std::vector<int> g_pipes;
std::vector<evpp_socket_t> g_pipes;
int numPipes;
int numActive;
int numWrites;
Expand All @@ -28,7 +28,7 @@ std::vector<std::shared_ptr<PipeEventWatcher>> g_pipe_event_watchers;

int g_reads, g_writes, g_fired;

void ReadCallbackOfFdChannel(int fd, int idx) {
void ReadCallbackOfFdChannel(evpp_socket_t fd, int idx) {
char ch = 'm';

g_reads += static_cast<int>(::recv(fd, &ch, sizeof(ch), 0));
Expand Down Expand Up @@ -88,7 +88,7 @@ std::pair<int, int> FdChannelRunOnce() {
std::pair<int, int> PipeEventWatcherRunOnce() {
Timestamp beforeInit(Timestamp::Now());
for (int i = 0; i < numActive; ++i) {
int fd = g_pipe_event_watchers[i]->wfd();
evpp_socket_t fd = g_pipe_event_watchers[i]->wfd();
::send(fd, "m", 1, 0);
}

Expand Down
2 changes: 1 addition & 1 deletion evpp/buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const char Buffer::kCRLF[] = "\r\n";
const size_t Buffer::kCheapPrependSize = 8;
const size_t Buffer::kInitialSize = 1024;

ssize_t Buffer::ReadFromFD(int fd, int* savedErrno) {
ssize_t Buffer::ReadFromFD(evpp_socket_t fd, int* savedErrno) {
// saved an ioctl()/FIONREAD call to tell how much to read
char extrabuf[65536];
struct iovec vec[2];
Expand Down
2 changes: 1 addition & 1 deletion evpp/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class EVPP_EXPORT Buffer {

// ReadFromFD reads data from a fd directly into buffer,
// and return result of readv, errno is saved into saved_errno
ssize_t ReadFromFD(int fd, int* saved_errno);
ssize_t ReadFromFD(evpp_socket_t fd, int* saved_errno);

// Next returns a slice containing the next n bytes from the buffer,
// advancing the buffer as if the bytes had been returned by Read.
Expand Down
4 changes: 2 additions & 2 deletions evpp/connector.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DNSResolver;
class TCPClient;
class EVPP_EXPORT Connector : public std::enable_shared_from_this<Connector> {
public:
typedef std::function<void(int sockfd, const std::string& /*local addr*/)> NewConnectionCallback;
typedef std::function<void(evpp_socket_t sockfd, const std::string& /*local addr*/)> NewConnectionCallback;
Connector(EventLoop* loop, TCPClient* client);
~Connector();
void Start();
Expand Down Expand Up @@ -54,7 +54,7 @@ class EVPP_EXPORT Connector : public std::enable_shared_from_this<Connector> {

Duration timeout_;

int fd_ = -1;
evpp_socket_t fd_ = -1;

// A flag indicate whether the Connector owns this fd.
// If the Connector owns this fd, the Connector has responsibility to close this fd.
Expand Down
10 changes: 5 additions & 5 deletions evpp/event_watcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void PipeEventWatcher::DoClose() {
}
}

void PipeEventWatcher::HandlerFn(int /*fd*/, short /*which*/, void* v) {
void PipeEventWatcher::HandlerFn(evpp_socket_t /*fd*/, short /*which*/, void* v) {
PipeEventWatcher* e = (PipeEventWatcher*)v;
#ifdef H_BENCHMARK_TESTING
// Every time we only read 1 byte for testing the IO event performance.
Expand Down Expand Up @@ -213,7 +213,7 @@ bool TimerEventWatcher::DoInit() {
return true;
}

void TimerEventWatcher::HandlerFn(int /*fd*/, short /*which*/, void* v) {
void TimerEventWatcher::HandlerFn(evpp_socket_t /*fd*/, short /*which*/, void* v) {
TimerEventWatcher* h = (TimerEventWatcher*)v;
h->handler_();
}
Expand All @@ -226,14 +226,14 @@ bool TimerEventWatcher::AsyncWait() {
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
SignalEventWatcher::SignalEventWatcher(int signo, EventLoop* loop,
SignalEventWatcher::SignalEventWatcher(signal_number_t signo, EventLoop* loop,
const Handler& handler)
: EventWatcher(loop->event_base(), handler)
, signo_(signo) {
assert(signo_);
}

SignalEventWatcher::SignalEventWatcher(int signo, EventLoop* loop,
SignalEventWatcher::SignalEventWatcher(signal_number_t signo, EventLoop* loop,
Handler&& h)
: EventWatcher(loop->event_base(), std::move(h))
, signo_(signo) {
Expand All @@ -246,7 +246,7 @@ bool SignalEventWatcher::DoInit() {
return true;
}

void SignalEventWatcher::HandlerFn(int /*sn*/, short /*which*/, void* v) {
void SignalEventWatcher::HandlerFn(signal_number_t /*sn*/, short /*which*/, void* v) {
SignalEventWatcher* h = (SignalEventWatcher*)v;
h->handler_();
}
Expand Down
14 changes: 7 additions & 7 deletions evpp/event_watcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ class EVPP_EXPORT PipeEventWatcher : public EventWatcher {

bool AsyncWait();
void Notify();
int wfd() const { return pipe_[0]; }
evpp_socket_t wfd() const { return pipe_[0]; }
private:
virtual bool DoInit();
virtual void DoClose();
static void HandlerFn(int fd, short which, void* v);
static void HandlerFn(evpp_socket_t fd, short which, void* v);

int pipe_[2]; // Write to pipe_[0] , Read from pipe_[1]
evpp_socket_t pipe_[2]; // Write to pipe_[0] , Read from pipe_[1]
};

class EVPP_EXPORT TimerEventWatcher : public EventWatcher {
Expand All @@ -77,20 +77,20 @@ class EVPP_EXPORT TimerEventWatcher : public EventWatcher {

private:
virtual bool DoInit();
static void HandlerFn(int fd, short which, void* v);
static void HandlerFn(evpp_socket_t fd, short which, void* v);
private:
Duration timeout_;
};

class EVPP_EXPORT SignalEventWatcher : public EventWatcher {
public:
SignalEventWatcher(int signo, EventLoop* loop, const Handler& handler);
SignalEventWatcher(int signo, EventLoop* loop, Handler&& handler);
SignalEventWatcher(signal_number_t signo, EventLoop* loop, const Handler& handler);
SignalEventWatcher(signal_number_t signo, EventLoop* loop, Handler&& handler);

bool AsyncWait();
private:
virtual bool DoInit();
static void HandlerFn(int sn, short which, void* v);
static void HandlerFn(signal_number_t sn, short which, void* v);

int signo_;
};
Expand Down
6 changes: 3 additions & 3 deletions evpp/fd_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace evpp {
static_assert(FdChannel::kReadable == EV_READ, "");
static_assert(FdChannel::kWritable == EV_WRITE, "");

FdChannel::FdChannel(EventLoop* l, int f, bool r, bool w)
FdChannel::FdChannel(EventLoop* l, evpp_socket_t f, bool r, bool w)
: loop_(l), attached_(false), event_(nullptr), fd_(f) {
DLOG_TRACE << "fd=" << fd_;
assert(fd_ > 0);
Expand Down Expand Up @@ -147,12 +147,12 @@ std::string FdChannel::EventsToString() const {
return s;
}

void FdChannel::HandleEvent(int sockfd, short which, void* v) {
void FdChannel::HandleEvent(evpp_socket_t sockfd, short which, void* v) {
FdChannel* c = (FdChannel*)v;
c->HandleEvent(sockfd, which);
}

void FdChannel::HandleEvent(int sockfd, short which) {
void FdChannel::HandleEvent(evpp_socket_t sockfd, short which) {
assert(sockfd == fd_);
DLOG_TRACE << "fd=" << sockfd << " " << EventsToString();

Expand Down
10 changes: 5 additions & 5 deletions evpp/fd_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class EVPP_EXPORT FdChannel {
typedef std::function<void()> ReadEventCallback;

public:
FdChannel(EventLoop* loop, int fd,
FdChannel(EventLoop* loop, evpp_socket_t fd,
bool watch_read_event, bool watch_write_event);
~FdChannel();

Expand Down Expand Up @@ -56,7 +56,7 @@ class EVPP_EXPORT FdChannel {
void DisableAllEvent();

public:
int fd() const {
evpp_socket_t fd() const {
return fd_;
}
std::string EventsToString() const;
Expand All @@ -71,8 +71,8 @@ class EVPP_EXPORT FdChannel {
}

private:
void HandleEvent(int fd, short which);
static void HandleEvent(int fd, short which, void* v);
void HandleEvent(evpp_socket_t fd, short which);
static void HandleEvent(evpp_socket_t fd, short which, void* v);

void Update();
void DetachFromLoop();
Expand All @@ -86,7 +86,7 @@ class EVPP_EXPORT FdChannel {
struct event* event_;
int events_; // the bitwise OR of zero or more of the EventType flags

int fd_;
evpp_socket_t fd_;
};

}
Expand Down
2 changes: 1 addition & 1 deletion evpp/libevent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "evpp/libevent.h"

#ifdef H_LIBEVENT_VERSION_14
struct event* event_new(struct event_base* base, int fd, short events,
struct event* event_new(struct event_base* base, evpp_socket_t fd, short events,
void(*cb)(int, short, void*), void* arg) {
struct event* ev;
ev = (struct event*)malloc(sizeof(struct event));
Expand Down
2 changes: 1 addition & 1 deletion evpp/libevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#ifdef H_LIBEVENT_VERSION_14
extern "C" {
struct evdns_base;
EVPP_EXPORT struct event* event_new(struct event_base* base, int fd, short events, void(*cb)(int, short, void*), void* arg);
EVPP_EXPORT struct event* event_new(struct event_base* base, evpp_socket_t fd, short events, void(*cb)(int, short, void*), void* arg);
EVPP_EXPORT void event_free(struct event* ev);
EVPP_EXPORT evhttp_connection* evhttp_connection_base_new(
struct event_base* base, struct evdns_base* dnsbase,
Expand Down
4 changes: 2 additions & 2 deletions evpp/listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class FdChannel;
class EVPP_EXPORT Listener {
public:
typedef std::function <
void(int sockfd,
void(evpp_socket_t sockfd,
const std::string& /*remote address with format "ip:port"*/,
const struct sockaddr_in* /*remote address*/) >
NewConnectionCallback;
Expand All @@ -33,7 +33,7 @@ class EVPP_EXPORT Listener {
void HandleAccept();

private:
int fd_ = -1;// The listening socket fd
evpp_socket_t fd_ = -1;// The listening socket fd
EventLoop* loop_;
std::string addr_;
std::unique_ptr<FdChannel> chan_;
Expand Down
24 changes: 12 additions & 12 deletions evpp/sockets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ std::string strerror(int e) {
}

namespace sock {
int CreateNonblockingSocket() {
evpp_socket_t CreateNonblockingSocket() {
int serrno = 0;

/* Create listen socket */
int fd = ::socket(AF_INET, SOCK_STREAM, 0);
evpp_socket_t fd = ::socket(AF_INET, SOCK_STREAM, 0);
if (fd == -1) {
serrno = errno;
LOG_ERROR << "socket error " << strerror(serrno);
Expand Down Expand Up @@ -65,8 +65,8 @@ int CreateNonblockingSocket() {
return INVALID_SOCKET;
}

int CreateUDPServer(int port) {
int fd = ::socket(AF_INET, SOCK_DGRAM, 0);
evpp_socket_t CreateUDPServer(int port) {
evpp_socket_t fd = ::socket(AF_INET, SOCK_DGRAM, 0);
if (fd == -1) {
int serrno = errno;
LOG_ERROR << "socket error " << strerror(serrno);
Expand Down Expand Up @@ -158,7 +158,7 @@ bool SplitHostPort(const char* address, std::string& host, int& port) {
return true;
}

struct sockaddr_storage GetLocalAddr(int sockfd) {
struct sockaddr_storage GetLocalAddr(evpp_socket_t sockfd) {
struct sockaddr_storage laddr;
memset(&laddr, 0, sizeof laddr);
socklen_t addrlen = static_cast<socklen_t>(sizeof laddr);
Expand Down Expand Up @@ -237,7 +237,7 @@ std::string ToIP(const struct sockaddr* s) {
return empty_string;
}

void SetTimeout(int fd, uint32_t timeout_ms) {
void SetTimeout(evpp_socket_t fd, uint32_t timeout_ms) {
#ifdef H_OS_WINDOWS
DWORD tv = timeout_ms;
#else
Expand All @@ -253,11 +253,11 @@ void SetTimeout(int fd, uint32_t timeout_ms) {
}
}

void SetTimeout(int fd, const Duration& timeout) {
void SetTimeout(evpp_socket_t fd, const Duration& timeout) {
SetTimeout(fd, (uint32_t)(timeout.Milliseconds()));
}

void SetKeepAlive(int fd, bool on) {
void SetKeepAlive(evpp_socket_t fd, bool on) {
int optval = on ? 1 : 0;
int rc = ::setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE,
reinterpret_cast<const char*>(&optval), static_cast<socklen_t>(sizeof optval));
Expand All @@ -267,7 +267,7 @@ void SetKeepAlive(int fd, bool on) {
}
}

void SetReuseAddr(int fd) {
void SetReuseAddr(evpp_socket_t fd) {
int optval = 1;
int rc = ::setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
reinterpret_cast<const char*>(&optval), static_cast<socklen_t>(sizeof optval));
Expand All @@ -277,7 +277,7 @@ void SetReuseAddr(int fd) {
}
}

void SetReusePort(int fd) {
void SetReusePort(evpp_socket_t fd) {
#ifdef SO_REUSEPORT
int optval = 1;
int rc = ::setsockopt(fd, SOL_SOCKET, SO_REUSEPORT,
Expand All @@ -290,7 +290,7 @@ void SetReusePort(int fd) {
}


void SetTCPNoDelay(int fd, bool on) {
void SetTCPNoDelay(evpp_socket_t fd, bool on) {
int optval = on ? 1 : 0;
int rc = ::setsockopt(fd, IPPROTO_TCP, TCP_NODELAY,
reinterpret_cast<const char*>(&optval), static_cast<socklen_t>(sizeof optval));
Expand All @@ -304,7 +304,7 @@ void SetTCPNoDelay(int fd, bool on) {
}

#ifdef H_OS_WINDOWS
int readv(int sockfd, struct iovec* iov, int iovcnt) {
int readv(evpp_socket_t sockfd, struct iovec* iov, int iovcnt) {
DWORD readn = 0;
DWORD flags = 0;

Expand Down
Loading

0 comments on commit b2535d7

Please sign in to comment.