Skip to content
This repository was archived by the owner on Apr 16, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
e310a70
Add .vscode directory to .gitignore
agauniyal Feb 9, 2017
04f61cf
Add partial socket class
agauniyal Feb 9, 2017
ea7ab39
Make net::methods inline for static lib builds
agauniyal Feb 9, 2017
522ed7c
Fix bug - message size < buffer size in read method
agauniyal Feb 9, 2017
6fb7e2b
Add safeguards to socket.read() method
agauniyal Feb 9, 2017
4591d38
Add send and recv methods to Socket
agauniyal Feb 11, 2017
f033e23
Add sendto/recvfrom overloads for send/recv methods
agauniyal Feb 11, 2017
13ce468
Refactoring - constexpr functions and pass by ref
agauniyal Feb 12, 2017
55099c7
Change sockaddr member to unique_ptr<sockaddr>
agauniyal Feb 12, 2017
3e1c339
Add getErrorMsg() function to net::method
tkhurana96 Feb 12, 2017
f7d39e4
Add -Wstrict-aliasing global flag
agauniyal Feb 15, 2017
ccfce2c
Make lockguard and use it to manage lockToErrorString
tkhurana96 Feb 15, 2017
5234896
Merge branch 'feature/socket' of https://github.com/c10k/net into fea…
tkhurana96 Feb 15, 2017
5ae9114
Make getErrorMsg() inline
tkhurana96 Feb 15, 2017
f3d9d33
Refactor error handling, add initial support for AF_UNIX (#2)
tkhurana96 Feb 19, 2017
b92d623
Refactor bind, connect and send methods to take callables
agauniyal Feb 21, 2017
586997d
Make most methods protocol independent
agauniyal Feb 21, 2017
da38118
Fix wrong return type inside decltype()
agauniyal Feb 21, 2017
38a3c3e
Add corresponding methods for getsockopt/setsockopt
agauniyal Feb 22, 2017
0e6cfa3
Merge pull request #3 from c10k/feature/socket-options
agauniyal Feb 22, 2017
5bc5d98
Try to add documentation in socket.hpp
tkhurana96 Feb 23, 2017
433a7dd
Add clang formatted doc and remove all 'Improve This' comments
tkhurana96 Feb 23, 2017
39e3e5b
Add documentation of functions in net::methods inside socket_family.hpp
tkhurana96 Feb 24, 2017
3c70d97
Organize documentation comments, change addrIpv* to addrIPv*
agauniyal Feb 24, 2017
d7a8a4b
Merge pull request #4 from c10k/documentation
agauniyal Feb 24, 2017
365cdd3
Try to add some constructor testing of Socket
tkhurana96 Mar 2, 2017
fcc9220
Add test for UDP unix socket
tkhurana96 Mar 2, 2017
eda83a6
Add some basic bind tests which needs revision
tkhurana96 Mar 2, 2017
813d36c
Try to complete the testing of Socket constructor and bind
tkhurana96 Mar 3, 2017
8341dc7
Rename test files for constructor and bind tests
tkhurana96 Mar 4, 2017
26b712b
Add some more tests to socket_constructor_test.cpp
tkhurana96 Mar 4, 2017
036b91e
Add socket options test
tkhurana96 Mar 4, 2017
bde8c00
Fix bug - unnecessary blocking of recv - improve send perf
agauniyal Mar 5, 2017
3f6bd69
Refactor SF namespace, ud-types and fix sign comparision warnings
agauniyal Mar 5, 2017
2df2edd
Add guards for port number inside construct methods
agauniyal Mar 6, 2017
1794747
Refactor SockOpt class into safer version
agauniyal Mar 6, 2017
f2d03b3
Add travis conf to repo
agauniyal Mar 6, 2017
07fe11a
Add libgtest-dev install step to travis conf
agauniyal Mar 6, 2017
559b965
Correct bind address in socket_bind_test.cpp
agauniyal Mar 6, 2017
f02db98
Move tests to non-failure mode temporarily
agauniyal Mar 6, 2017
1fdda3a
Merge pull request #5 from c10k/feature/ci
agauniyal Mar 6, 2017
c9bd2c5
Update README.md with introduction
agauniyal Mar 6, 2017
20e5c87
Add logo to README.md
agauniyal Mar 6, 2017
4f034ed
Add initial Socket Send tests for IPv4 and IPv6
tkhurana96 Mar 11, 2017
7a55527
Revamp Socket Send tests
tkhurana96 Mar 11, 2017
e47c764
Again revamp Socket Send tests but needs attention for -- Resolve Thi…
tkhurana96 Mar 11, 2017
f374670
Add test for recv and send methods for Socket
tkhurana96 Mar 17, 2017
4a4c797
Add wercker.yml config to repo
agauniyal Mar 21, 2017
20ef525
Add default clang build pipelint to wercker config
agauniyal Mar 21, 2017
b45d0eb
Add more build pipelines to wercker config
agauniyal Mar 21, 2017
691ae6b
Rename start-build pipeline to build
agauniyal Mar 21, 2017
2f2600b
Add default build pipeline
agauniyal Mar 21, 2017
8e44192
Rename default build pipeline to dev
agauniyal Mar 21, 2017
55efd5d
Improve socket constructor tests
agauniyal Mar 21, 2017
8c318d0
Modify test command for build pipelines
agauniyal Mar 21, 2017
eb45d09
Add travis, codecov and wercker badges in README
agauniyal Mar 21, 2017
953d1f5
Merge pull request #9 from c10k/ci/wercker
agauniyal Mar 21, 2017
1885a85
Add initial socket connect method tests
agauniyal Mar 21, 2017
4598ef8
Merge pull request #10 from c10k/test/socket_connect
agauniyal Mar 21, 2017
a1b0f67
Refactor tests, Add valgrind suite, address sanitizer builds
agauniyal Mar 21, 2017
aea422c
Add required permissions for executing tests on CI builds
agauniyal Mar 21, 2017
386d638
Comment out Socket Debug option test temporarily
agauniyal Mar 21, 2017
56c7146
Merge pull request #11 from c10k/refactor/tests
agauniyal Mar 21, 2017
eda845b
Revamp socket_send_test.cpp and socket_recv_test.cpp
tkhurana96 Mar 21, 2017
64a6b9f
Merge branch 'feature/socket' into recvTesting
agauniyal Mar 21, 2017
7d0c27f
Merge pull request #8 from c10k/recvTesting
agauniyal Mar 21, 2017
01dde9b
Add delay to valgrind test suite pipeline
agauniyal Mar 21, 2017
0728c70
Increase delays b/w pipeline commands
agauniyal Mar 21, 2017
19ffaf6
-> Fix TIME_WAIT thing for send and recv tests.
tkhurana96 Mar 21, 2017
4030306
Merge pull request #12 from c10k/lambdaReturnValueFix
agauniyal Mar 22, 2017
afae138
Fix generation of lcov reports
agauniyal Mar 22, 2017
7865355
Add coverage step to default gcc build
agauniyal Mar 22, 2017
846dd7b
Remove Travis CI
agauniyal Mar 22, 2017
5d6943b
Merge pull request #13 from c10k/feature/coverage
agauniyal Mar 22, 2017
a66e682
Add memset call before accepting user struct
agauniyal Mar 22, 2017
b563379
Merge pull request #14 from c10k/test/memset-all-structs
agauniyal Mar 22, 2017
74ecc92
Add tests for read and write calls of Socket
tkhurana96 Mar 22, 2017
9203cc2
Remove memset that set socket structures to 0 and remove all --return…
tkhurana96 Mar 22, 2017
c18c3e6
Extract SO_DEBUG Test to seperate test file
agauniyal Mar 23, 2017
5c44849
Merge pull request #17 from c10k/fix/SO_DEBUG
agauniyal Mar 23, 2017
a5316bc
Add tests for SNDTIMEO & RCVTIMEO socket options
agauniyal Mar 23, 2017
660a840
Add Opt equality tests
agauniyal Mar 23, 2017
410b45d
Add connect, bind, read, write tests for unix socket
tkhurana96 Mar 23, 2017
b40869a
Merge pull request #18 from c10k/test/socket-timeout
agauniyal Mar 23, 2017
e7037a3
Add unix udp client and server examples
tkhurana96 Mar 23, 2017
671f2ed
Add read and write tests for unix udp socket
tkhurana96 Mar 23, 2017
45f9b09
Add send and recv tests for unix sockets
tkhurana96 Mar 23, 2017
830cd2d
Use c_str, instead of front, of std::string
tkhurana96 Mar 23, 2017
0d62f15
Complete unix socket send and recv testing
tkhurana96 Mar 24, 2017
720028d
Merge pull request #19 from c10k/improveCoverage
agauniyal Mar 24, 2017
dca777c
Merge pull request #6 from c10k/feature/socket
agauniyal Mar 24, 2017
326aee8
Add examples for multithreaded, fork server
agauniyal Apr 1, 2017
d042a0f
Add try-catch block for worker_thread
agauniyal Apr 1, 2017
0bd40b9
Merge pull request #20 from c10k/feature/add-examples
agauniyal Apr 1, 2017
a232689
Fix move constructor & private constructor bugs
agauniyal Apr 2, 2017
6b2d18a
Merge pull request #22 from c10k/fix/minor-bugs
agauniyal Apr 2, 2017
393fe47
Reap Zombie child processes in tcp_fork server example
agauniyal Apr 4, 2017
afb25d1
Merge pull request #23 from c10k/fix/zombie-processes
agauniyal Apr 4, 2017
73540fb
Update README with examples
agauniyal Jun 4, 2017
19a866b
Fix wercker builds
agauniyal Jun 4, 2017
84d319f
Revert "Fix wercker builds"
agauniyal Jun 4, 2017
a178d2f
Install locales before building
agauniyal Jun 4, 2017
87aeaaf
Fix builds - gcc6 broken
agauniyal Jun 4, 2017
50abf24
Add gcc7 compiler to builds
agauniyal Jun 4, 2017
8ded159
Merge pull request #24 from c10k/add/documentation
agauniyal Jun 4, 2017
8a8e8cf
Add TCP_NODELAY and TCP_MAXSEG options
agauniyal Jun 4, 2017
aa7af58
Fix socket_options_test from failing due to TCP_MAX_SEG
agauniyal Jul 2, 2017
f6c074e
Merge pull request #25 from c10k/feature/tcp-socket-options
agauniyal Jul 2, 2017
fe6c381
Add autogenerated docs
agauniyal Sep 13, 2017
f9c8c6f
Remove concurrent threaded example from README
agauniyal Sep 13, 2017
8f74a5d
Reformat source files with new clang-format
agauniyal Sep 13, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
Language: Cpp
AccessModifierOffset: -4
AlignAfterOpenBracket: DontAlign
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false
Expand Down Expand Up @@ -40,7 +40,7 @@ MaxEmptyLinesToKeep: 2
NamespaceIndentation: Inner
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SortIncludes: false
SpaceAfterCStyleCast: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
Expand All @@ -53,5 +53,5 @@ SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: ForIndentation
UseTab: Never
...
4 changes: 1 addition & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@
root = true

[*]
indent_style = tab
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{html,ejs,css,sass,scss,js,yml}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false

[{package.json,.travis.yml}]
indent_style = space
indent_size = 2
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@

# Directories
build

.vscode
.wercker
148 changes: 146 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,146 @@
# net
Modern C++ network programming library
# NET [![codecov](https://codecov.io/gh/c10k/net/branch/master/graph/badge.svg)](https://codecov.io/gh/c10k/net)

![Logo](https://cloud.githubusercontent.com/assets/7630575/23608808/1e1de904-0291-11e7-8c6a-003f7a29e59c.png)

#### Net is a High-level & Efficient Modern C++ library for Network Programming.

[![wercker status](https://app.wercker.com/status/945fa8542bfa8066980fc234e4e91aee/m/ "wercker status")](https://app.wercker.com/project/byKey/945fa8542bfa8066980fc234e4e91aee)

# Introduction

It uses standard library functions with no other dependencies and provides a safer yet expressive version of original Berkeley Sockets API. Common mistakes are abstracted away giving a boost in productivity for library user.

```cpp
#include "socket.hpp"
#include <iostream>

using namespace net;

int main()
{
try {
Socket s(Domain::IPv4, Type::TCP);
s.start("127.0.0.1", 24000);
while (true) {
const auto peer = s.accept();
const auto msg = peer.recv(15);
std::cout << msg << '\n';
}
} catch (std::exception &e) {
std::cerr << e.what() << '\n';
}
}
```


# Getting Started

You don't need anything else other than a supported platform, a C++14 compiler and a few seconds to spare. The library is currently uses meson build system so first class dependency management is included for those using same. Otherwise just `git clone` the library, and pass the includes and sources to your compiler and you're good to go.

## Documentation

Please take a look inside `docs/` directory to find API and other documentation.

## Build with Meson

```bash
git clone https://github.com/c10k/net.git
cd net
mkdir build && cd build
meson .. && ninja # This will also create a dynamic lib
```

## Testing with GTest

```bash
git clone https://github.com/c10k/net.git
cd net
mkdir build && cd build
meson .. && ninja
./test/testexe
```


# Examples

You can see more examples under `examples/` directory.

## Echo TCP server

```cpp
#include "socket.hpp"
#include <iostream>

using namespace net;

int main()
{
try {
Socket s(Domain::IPv4, Type::TCP);
s.start("127.0.0.1", 24000);
while (true) {
const auto peer = s.accept();
const auto msg = peer.recv(15);
std::cout << msg << '\n';
}
} catch (std::exception &e) {
std::cerr << e.what() << '\n';
}
}
```

## Hello World TCP client

```cpp
#include "socket.hpp"
#include <iostream>

using namespace net;

int main()
{
try {
Socket s(Domain::IPv4, Type::TCP);
s.connect("0.0.0.0", 24000);
s.send("Hello World!");
} catch (std::exception &e) {
std::cerr << e.what() << '\n';
}
}
```

## Concurrent TCP server with fork

```cpp
#include "socket.hpp"
#include <iostream>
#include <signal.h>

using namespace net;

int main()
{
try {
signal(SIGCHLD, SIG_IGN);
Socket s(Domain::IPv4, Type::TCP);
s.start("127.0.0.1", 24001);

while (true) {
const auto peer = s.accept();
if (!fork()) {
std::cout << peer.recv(10) << '\n';
return 0;
}
}
} catch (std::exception &e) {
std::cerr << e.what() << '\n';
}
}
```

# TODO
- [ ] Proper namespacing in socket options
- [ ] Add more unit tests, increase coverage
- [ ] Add examples for non-blocking socket operations
- [ ] Add support for more protocols other than TCP, UDP, UNIX
- [ ] Add benchmarks against popular alternatives
Loading