Skip to content

Commit 113ce41

Browse files
committed
add vs 2017 project
1 parent 820eeda commit 113ce41

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+23454
-0
lines changed

src/redis/redis.sln

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.27703.2035
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "redis", "redis\redis.vcxproj", "{80D62D1F-BDEC-446E-BC7C-D17268B3457F}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{80D62D1F-BDEC-446E-BC7C-D17268B3457F}.Debug|x64.ActiveCfg = Debug|x64
17+
{80D62D1F-BDEC-446E-BC7C-D17268B3457F}.Debug|x64.Build.0 = Debug|x64
18+
{80D62D1F-BDEC-446E-BC7C-D17268B3457F}.Debug|x86.ActiveCfg = Debug|Win32
19+
{80D62D1F-BDEC-446E-BC7C-D17268B3457F}.Debug|x86.Build.0 = Debug|Win32
20+
{80D62D1F-BDEC-446E-BC7C-D17268B3457F}.Release|x64.ActiveCfg = Release|x64
21+
{80D62D1F-BDEC-446E-BC7C-D17268B3457F}.Release|x64.Build.0 = Release|x64
22+
{80D62D1F-BDEC-446E-BC7C-D17268B3457F}.Release|x86.ActiveCfg = Release|Win32
23+
{80D62D1F-BDEC-446E-BC7C-D17268B3457F}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {34BAA9D4-2C26-4368-A0F4-571B8A73277D}
30+
EndGlobalSection
31+
EndGlobal

src/redis/redis/acceptor.cc

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include "acceptor.h"
2+
#include "log.h"
3+
4+
Acceptor::Acceptor(EventLoop *loop, const char *ip, int16_t port)
5+
:loop(loop),
6+
channel(loop, Socket::createTcpSocket(ip, port)),
7+
sockfd(channel.getfd()),
8+
#ifndef _WIN32
9+
idleFd(::open("/dev/null", O_RDONLY | O_CLOEXEC)),
10+
#endif
11+
listenning(false)
12+
{
13+
#ifndef _WIN32
14+
assert(idleFd >= 0);
15+
#endif
16+
channel.setReadCallback(std::bind(&Acceptor::handleRead, this));
17+
}
18+
19+
Acceptor::~Acceptor()
20+
{
21+
channel.disableAll();
22+
channel.remove();
23+
Socket::close(sockfd);
24+
}
25+
26+
void Acceptor::handleRead()
27+
{
28+
loop->assertInLoopThread();
29+
struct sockaddr_in6 address;
30+
socklen_t len = sizeof(address);
31+
#ifdef __linux__
32+
int32_t connfd = ::accept4(sockfd, (struct sockaddr*)&address,
33+
&len, SOCK_NONBLOCK | SOCK_CLOEXEC);
34+
#else
35+
int32_t connfd = ::accept(sockfd, (struct sockaddr*)&address, &len);
36+
#endif
37+
38+
if (connfd >= 0)
39+
{
40+
if (newConnectionCallback)
41+
{
42+
socket.setSocketNonBlock(connfd);
43+
newConnectionCallback(connfd);
44+
}
45+
else
46+
{
47+
Socket::close(sockfd);
48+
}
49+
}
50+
else
51+
{
52+
53+
}
54+
}
55+
56+
void Acceptor::listen()
57+
{
58+
loop->assertInLoopThread();
59+
listenning = true;
60+
channel.enableReading();
61+
}

src/redis/redis/acceptor.h

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#pragma once
2+
#include "all.h"
3+
#include "channel.h"
4+
#include "eventloop.h"
5+
#include "socket.h"
6+
7+
class Acceptor
8+
{
9+
public:
10+
typedef std::function<void(int32_t)> NewConnectionCallback;
11+
Acceptor(EventLoop *loop, const char *ip, int16_t port);
12+
~Acceptor();
13+
14+
void setNewConnectionCallback(const NewConnectionCallback &&cb)
15+
{
16+
newConnectionCallback = std::move(cb);
17+
}
18+
19+
bool getlistenning() const
20+
{
21+
return listenning;
22+
}
23+
24+
void listen();
25+
void handleRead();
26+
27+
private:
28+
Acceptor(const Acceptor&);
29+
void operator=(const Acceptor&);
30+
31+
EventLoop *loop;
32+
Socket socket;
33+
Channel channel;
34+
int32_t sockfd;
35+
36+
NewConnectionCallback newConnectionCallback;
37+
bool listenning;
38+
bool idleFd;
39+
};

0 commit comments

Comments
 (0)