Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc6dd632

Browse files
committed
Initial implementation of sessions.
1 parente963b4a commitc6dd632

File tree

7 files changed

+278
-161
lines changed

7 files changed

+278
-161
lines changed

‎http/src/CMakeLists.txt

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,6 @@ if (OPENSSL_FOUND)
1818
include_directories(${OPENSSL_INCLUDE_DIR})
1919
endif()
2020

21-
if (${CMAKE_CXX_COMPILER_ID}MATCHESGNU)
22-
if (HAVE_STD11)
23-
set(CPP-NETLIB_CXXFLAGS"-Wall -std=c++11")
24-
elseif (HAVE_STD0X)
25-
set(CPP-NETLIB_CXXFLAGS"-Wall -std=c++0x")
26-
endif()
27-
elseif (${CMAKE_CXX_COMPILER_ID}MATCHESClang)
28-
CHECK_CXX_COMPILER_FLAG(-std=c++11HAVE_STD11)
29-
if (CPP-NETLIB_DISABLE_LIBCXX)
30-
set(CPP-NETLIB_CXXFLAGS"-Wall -std=c++11")
31-
else()
32-
set(CPP-NETLIB_CXXFLAGS"-Wall -std=c++11 -stdlib=libc++")
33-
endif()
34-
endif()
35-
3621
set(CPP-NETLIB_HTTP_MESSAGE_SRCShttp/request.cpphttp/response.cpp)
3722
add_library(cppnetlib-http-message${CPP-NETLIB_HTTP_MESSAGE_SRCS})
3823
add_dependencies(cppnetlib-http-message
@@ -41,27 +26,9 @@ add_dependencies(cppnetlib-http-message
4126
target_link_libraries(cppnetlib-http-message
4227
${Boost_LIBRARIES}
4328
cppnetlib-message)
44-
foreach (src_file${CPP-NETLIB_HTTP_MESSAGE_SRCS})
45-
if (${CMAKE_CXX_COMPILER_ID}MATCHESGNU)
46-
set_source_files_properties(${src_file}
47-
PROPERTIESCOMPILE_FLAGS${CPP-NETLIB_CXXFLAGS})
48-
elseif (${CMAKE_CXX_COMPILER_ID}MATCHESClang)
49-
set_source_files_properties(${src_file}
50-
PROPERTIESCOMPILE_FLAGS${CPP-NETLIB_CXXFLAGS})
51-
endif()
52-
endforeach(src_file)
5329

5430
set(CPP-NETLIB_HTTP_MESSAGE_WRAPPERS_SRCShttp/message/wrappers.cpp)
5531
add_library(cppnetlib-http-message-wrappers${CPP-NETLIB_HTTP_MESSAGE_WRAPPERS_SRCS})
56-
foreach (src_file${CPP-NETLIB_HTTP_MESSAGE_WRAPPERS_SRCS})
57-
if (${CMAKE_CXX_COMPILER_ID}MATCHESGNU)
58-
set_source_files_properties(${src_file}
59-
PROPERTIESCOMPILE_FLAGS${CPP-NETLIB_CXXFLAGS})
60-
elseif (${CMAKE_CXX_COMPILER_ID}MATCHESClang)
61-
set_source_files_properties(${src_file}
62-
PROPERTIESCOMPILE_FLAGS${CPP-NETLIB_CXXFLAGS})
63-
endif()
64-
endforeach(src_file)
6532

6633
#set(CPP-NETLIB_HTTP_SERVER_PARSERS_SRCS server_request_parsers_impl.cpp)
6734
#add_library(cppnetlib-http-server-parsers ${CPP-NETLIB_HTTP_SERVER_PARSERS_SRCS})
@@ -129,15 +96,6 @@ set(CPP-NETLIB_HTTP_CLIENT_CONNECTIONS_SRCS
12996
http/client_async_resolver.cpp
13097
http/client_connection_normal.cpp)
13198
add_library(cppnetlib-http-client-connections${CPP-NETLIB_HTTP_CLIENT_CONNECTIONS_SRCS})
132-
foreach (src_file${CPP-NETLIB_HTTP_CLIENT_CONNECTIONS_SRCS})
133-
if (${CMAKE_CXX_COMPILER_ID}MATCHESGNU)
134-
set_source_files_properties(${src_file}
135-
PROPERTIESCOMPILE_FLAGS${CPP-NETLIB_CXXFLAGS})
136-
elseif (${CMAKE_CXX_COMPILER_ID}MATCHESClang)
137-
set_source_files_properties(${src_file}
138-
PROPERTIESCOMPILE_FLAGS${CPP-NETLIB_CXXFLAGS})
139-
endif()
140-
endforeach(src_file)
14199

142100
set(CPP-NETLIB_HTTP_CLIENT_SRCS
143101
http/client.cpp)
@@ -165,24 +123,10 @@ target_link_libraries(cppnetlib-http-client
165123
cppnetlib-http-message-wrappers
166124
cppnetlib-http-client-connections
167125
)
168-
foreach (src_file${CPP-NETLIB_HTTP_CLIENT_SRCS})
169-
if (${CMAKE_CXX_COMPILER_ID}MATCHESGNU)
170-
set_source_files_properties(${src_file}
171-
PROPERTIESCOMPILE_FLAGS${CPP-NETLIB_CXXFLAGS})
172-
elseif (${CMAKE_CXX_COMPILER_ID}MATCHESClang)
173-
set_source_files_properties(${src_file}
174-
PROPERTIESCOMPILE_FLAGS${CPP-NETLIB_CXXFLAGS})
175-
endif()
176-
endforeach(src_file)
177126

178127
set(CPP-NETLIB_CONSTANTS_SRCSconstants.cpp)
179128
add_library(cppnetlib-constants${CPP-NETLIB_CONSTANTS_SRCS})
180-
foreach (src_file${CPP-NETLIB_CONSTANTS_SRCS})
181-
if (${CMAKE_CXX_COMPILER_ID}MATCHESGNU)
182-
set_source_files_properties(${src_file}
183-
PROPERTIESCOMPILE_FLAGS${CPP-NETLIB_CXXFLAGS})
184-
elseif (${CMAKE_CXX_COMPILER_ID}MATCHESClang)
185-
set_source_files_properties(${src_file}
186-
PROPERTIESCOMPILE_FLAGS${CPP-NETLIB_CXXFLAGS})
187-
endif()
188-
endforeach(src_file)
129+
130+
# Server implementation files.
131+
set(CPP-NETLIB_HTTP_SERVER_SRCShttp/server/session.cpphttp/server/simple_sessions.cpp)
132+
add_library(cppnetlib-http-server${CPP-NETLIB_HTTP_SERVER_SRCS})

‎http/src/http/server.hpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2013 (c) Google, Inc.
2+
// Copyright 2013 (c) Dean Michael Berris <dberris@google.com>
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#ifndef NETWORK_HTTP_SERVER_HPP_20130327
8+
#defineNETWORK_HTTP_SERVER_HPP_20130327
9+
10+
#include<memory>
11+
#include<utility>
12+
#include<functional>
13+
#include<boost/utility/string_ref.hpp>
14+
15+
namespacenetwork {
16+
namespacehttp {
17+
18+
structdynamic_dispatcher;
19+
structsimple_sessions;
20+
structno_auth;
21+
structdefault_connection_manager;
22+
23+
template<classHandler = dynamic_dispatcher,
24+
classSessionManager = simple_sessions,classAuthenticator = no_auth,
25+
classConnectionManager = default_connection_manager>
26+
structbasic_server {
27+
voidregister_handler(
28+
boost::string_ref spec,
29+
std::function<void(
30+
typename SessionManager::session &,
31+
std::shared_ptr<typename ConnectionManager::connection>)> handler);
32+
};
33+
34+
typedef basic_server<> server;
35+
36+
}// namespace http
37+
}// namespace network
38+
39+
#endif/* end of include guard: NETWORK_HTTP_SERVER_HPP_20130327*/
40+

‎http/src/http/server/session.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2013 (c) Google, Inc.
2+
// Copyright 2013 (c) Dean Michael Berris <dberris@google.com>
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#include<http/server/session.hpp>
8+
9+
namespacenetwork {
10+
namespacehttp {
11+
12+
std::stringsession::get(boost::string_ref key, boost::string_ref value)const {
13+
session_map_type::const_iterator entry = session_map_.find(
14+
static_cast<std::string>(key));
15+
return entry == session_map_.end() ?static_cast<std::string>(value) :
16+
entry->second.second;
17+
}
18+
19+
voidsession::set(boost::string_ref key, boost::string_ref value,
20+
bool server_only) {
21+
auto new_value =make_pair(server_only,static_cast<std::string>(value));
22+
std::pair<session_map_type::iterator,bool> result =
23+
session_map_.insert(make_pair(static_cast<std::string>(key), new_value));
24+
if (!result.second)
25+
result.first->second =std::move(new_value);
26+
}
27+
28+
std::string session::operator[](boost::string_ref key)const {
29+
returnget(key,"");
30+
}
31+
32+
}// namespace http
33+
}// namespace network

‎http/src/http/server/session.hpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2013 (c) Google, Inc.
2+
// Copyright 2013 (c) Dean Michael Berris <dberris@google.com>
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#ifndef NETWORK_HTTP_SERVER_SESSION_HPP_20130405
8+
#defineNETWORK_HTTP_SERVER_SESSION_HPP_20130405
9+
10+
#include<string>
11+
#include<unordered_map>
12+
#include<boost/utility/string_ref.hpp>
13+
14+
namespacenetwork {
15+
namespacehttp {
16+
17+
structsession {
18+
session() =default;
19+
session(const session&) =default;
20+
session(session&&) =default;
21+
session&operator=(const session&) =default;
22+
session&operator=(session&&) =default;
23+
24+
voidset(boost::string_ref key, boost::string_ref value,bool server_only =false);
25+
std::stringget(boost::string_ref key, boost::string_ref default_value)const;
26+
std::stringoperator[](boost::string_ref key)const;
27+
private:
28+
typedef std::unordered_map<std::string, std::pair<bool, std::string>> session_map_type;
29+
session_map_type session_map_;
30+
};
31+
32+
}// namespace http
33+
}// namespace network
34+
35+
#endif/* end of include guard: NETWORK_HTTP_SERVER_SESSION_HPP_20130405*/
36+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2013 (c) Google, Inc.
2+
// Copyright 2013 (c) Dean Michael Berris <dberris@google.com>
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#include<http/server/simple_sessions.hpp>
8+
9+
namespacenetwork {
10+
namespacehttp {
11+
12+
session&simple_sessions::lookup(boost::string_ref session_id) {
13+
std::string real_session_id = session_id.empty() ?
14+
std::to_string(next_session_id_.fetch_add(1, std::memory_order::memory_order_seq_cst))
15+
:static_cast<std::string>(session_id);
16+
std::pair<session_map_type::iterator,bool> result =
17+
sessions_.insert(make_pair(std::move(real_session_id),session()));
18+
result.first->second.set("id", real_session_id);
19+
return result.first->second;
20+
}
21+
22+
}// namespace http
23+
}// namespace network
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2013 (c) Google, Inc.
2+
// Copyright 2013 (c) Dean Michael Berris <dberris@google.com>
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#ifndef NETWORK_HTTP_SERVER_SIMPLE_SESSIONS_HPP_20130327
8+
#defineNETWORK_HTTP_SERVER_SIMPLE_SESSIONS_HPP_20130327
9+
10+
#include<unordered_map>
11+
#include<http/server/session.hpp>
12+
#include<boost/utility/string_ref.hpp>
13+
#include<atomic>
14+
15+
namespacenetwork {
16+
namespacehttp {
17+
18+
structsimple_sessions {
19+
simple_sessions() =default;
20+
simple_sessions(const simple_sessions&) =delete;
21+
simple_sessions(simple_sessions&&) =delete;
22+
simple_sessions&operator=(const simple_sessions&) =delete;
23+
simple_sessions&operator=(simple_sessions&) =delete;
24+
25+
session &lookup(boost::string_ref session_id);
26+
private:
27+
typedef std::unordered_map<std::string, session> session_map_type;
28+
session_map_type sessions_;
29+
std::atomic_uint_fast64_t next_session_id_;
30+
};
31+
32+
}// namespace http
33+
}// namespace network
34+
35+
#endif/* end of include guard: NETWORK_HTTP_SERVER_SIMPLE_SESSIONS_HPP_20130327*/
36+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp