-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 94004ba
Showing
6 changed files
with
468 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
cmake-build-debug | ||
build | ||
.idea | ||
.vagrant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
cmake_minimum_required(VERSION 2.8) | ||
project(tcp-client) | ||
set(EXE_NAME tcp-client) | ||
set(CMAKE_PREFIX_PATH ${PROJECT_SOURCE_DIR}/deps/cmake) | ||
set(CMAKE_C_STANDARD 99) | ||
aux_source_directory(./src SOURCE_FILES) | ||
#优先static | ||
SET(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) | ||
|
||
#数学库 | ||
list(APPEND DEPS_LIB m) | ||
|
||
add_executable(${EXE_NAME} ${SOURCE_FILES}) | ||
|
||
#多线程支持 | ||
find_package(Threads REQUIRED) | ||
if (THREADS_HAVE_PTHREAD_ARG) | ||
target_compile_options(PUBLIC ${EXE_NAME} "-pthread") | ||
endif () | ||
if (CMAKE_THREAD_LIBS_INIT) | ||
list(APPEND DEPS_LIB ${CMAKE_THREAD_LIBS_INIT}) | ||
endif () | ||
|
||
find_package(FindPCAP) | ||
if (PCAP_FOUND) | ||
include_directories(${PCAP_INCLUDE_DIR}) | ||
list(APPEND DEPS_LIB ${PCAP_LIBRARY}) | ||
else () | ||
message(FATAL_ERROR "libpcap not found!") | ||
endif () | ||
find_package(FindLibNet) | ||
if (LIBNET_FOUND) | ||
include_directories(${LIBNET_INCLUDE_DIR}) | ||
list(APPEND DEPS_LIB ${LIBNET_LIBRARIES}) | ||
else () | ||
message(FATAL_ERROR "libnet not found!") | ||
endif () | ||
target_link_libraries(${EXE_NAME} ${DEPS_LIB}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*百万级TCP测试工具 | ||
|
||
参考《模拟百万级TCP并发》 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# - Find libnet | ||
# | ||
# -*- cmake -*- | ||
# | ||
# Find the libnet module | ||
# | ||
# LIBNET_INCLUDE_DIR - where to find libnet.h, etc. | ||
# LIBNET_LIBRARIES - List of libraries when using LibNet. | ||
# LIBNET_FOUND - True if libnet found. | ||
|
||
IF (LIBNET_INCLUDE_DIR) | ||
# Already in cache, be silent | ||
SET(LIBNET_FIND_QUIETLY TRUE) | ||
ENDIF (LIBNET_INCLUDE_DIR) | ||
|
||
FIND_PATH(LIBNET_INCLUDE_DIR libnet.h | ||
/usr/include | ||
) | ||
|
||
SET(LIBNET_NAMES net) | ||
FIND_LIBRARY(LIBNET_LIBRARY | ||
NAMES ${LIBNET_NAMES} | ||
PATHS /usr/lib /usr/local/lib | ||
PATH_SUFFIXES libnet | ||
) | ||
|
||
ADD_DEFINITIONS(-DLIBNET_LIL_ENDIAN=1) | ||
|
||
IF (LIBNET_INCLUDE_DIR AND LIBNET_LIBRARY) | ||
SET(LIBNET_FOUND TRUE) | ||
SET(LIBNET_LIBRARIES ${LIBNET_LIBRARY} ) | ||
|
||
ELSE (LIBNET_INCLUDE_DIR AND LIBNET_LIBRARY) | ||
SET(LIBNET_FOUND FALSE) | ||
SET(LIBNET_LIBRARIES ) | ||
ENDIF (LIBNET_INCLUDE_DIR AND LIBNET_LIBRARY) | ||
|
||
IF (LIBNET_FOUND) | ||
IF (NOT LIBNET_FIND_QUIETLY) | ||
MESSAGE(STATUS "Found LibNet: ${LIBNET_LIBRARY}") | ||
ENDIF (NOT LIBNET_FIND_QUIETLY) | ||
ELSE (LIBNET_FOUND) | ||
IF (LIBNET_FIND_REQUIRED) | ||
MESSAGE(STATUS "Looked for LibNet libraries named ${LIBNET_NAMES}.") | ||
MESSAGE(FATAL_ERROR "Could NOT find LibNet library") | ||
ENDIF (LIBNET_FIND_REQUIRED) | ||
ENDIF (LIBNET_FOUND) | ||
|
||
MARK_AS_ADVANCED( | ||
LIBNET_LIBRARY | ||
LIBNET_INCLUDE_DIR | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# - Try to find libpcap include dirs and libraries | ||
# | ||
# Usage of this module as follows: | ||
# | ||
# find_package(PCAP) | ||
# | ||
# Variables used by this module, they can change the default behaviour and need | ||
# to be set before calling find_package: | ||
# | ||
# PCAP_ROOT_DIR Set this variable to the root installation of | ||
# libpcap if the module has problems finding the | ||
# proper installation path. | ||
# | ||
# Variables defined by this module: | ||
# | ||
# PCAP_FOUND System has libpcap, include and library dirs found | ||
# PCAP_INCLUDE_DIR The libpcap include directories. | ||
# PCAP_LIBRARY The libpcap library (possibly includes a thread | ||
# library e.g. required by pf_ring's libpcap) | ||
# HAVE_PF_RING If a found version of libpcap supports PF_RING | ||
|
||
find_path(PCAP_ROOT_DIR | ||
NAMES include/pcap.h | ||
) | ||
|
||
find_path(PCAP_INCLUDE_DIR | ||
NAMES pcap.h | ||
HINTS ${PCAP_ROOT_DIR}/include | ||
) | ||
|
||
find_library(PCAP_LIBRARY | ||
NAMES pcap | ||
HINTS ${PCAP_ROOT_DIR}/lib | ||
) | ||
|
||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args(PCAP DEFAULT_MSG | ||
PCAP_LIBRARY | ||
PCAP_INCLUDE_DIR | ||
) | ||
|
||
include(CheckCSourceCompiles) | ||
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY}) | ||
check_c_source_compiles("int main() { return 0; }" PCAP_LINKS_SOLO) | ||
set(CMAKE_REQUIRED_LIBRARIES) | ||
|
||
# check if linking against libpcap also needs to link against a thread library | ||
if (NOT PCAP_LINKS_SOLO) | ||
find_package(Threads) | ||
if (THREADS_FOUND) | ||
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY} ${CMAKE_THREAD_LIBS_INIT}) | ||
check_c_source_compiles("int main() { return 0; }" PCAP_NEEDS_THREADS) | ||
set(CMAKE_REQUIRED_LIBRARIES) | ||
endif () | ||
if (THREADS_FOUND AND PCAP_NEEDS_THREADS) | ||
set(_tmp ${PCAP_LIBRARY} ${CMAKE_THREAD_LIBS_INIT}) | ||
list(REMOVE_DUPLICATES _tmp) | ||
set(PCAP_LIBRARY ${_tmp} | ||
CACHE STRING "Libraries needed to link against libpcap" FORCE) | ||
else () | ||
message(FATAL_ERROR "Couldn't determine how to link against libpcap") | ||
endif () | ||
endif () | ||
|
||
include(CheckFunctionExists) | ||
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY}) | ||
check_function_exists(pcap_get_pfring_id HAVE_PF_RING) | ||
set(CMAKE_REQUIRED_LIBRARIES) | ||
|
||
mark_as_advanced( | ||
PCAP_ROOT_DIR | ||
PCAP_INCLUDE_DIR | ||
PCAP_LIBRARY | ||
) |
Oops, something went wrong.