Commit 18a2dbfb20e6c43987c65789a29ebfcb75dedaf8
1 parent
ea9eaf95
Fixed paths
Showing
26 changed files
with
191 additions
and
960 deletions
examples/linux/canrecv.cpp
| 1 | -// canrecv.cpp | ||
| 2 | -// | ||
| 3 | -// Linux SoxketCAN reader example. | ||
| 4 | -// | ||
| 5 | -// | ||
| 6 | -// -------------------------------------------------------------------------- | ||
| 7 | -// This file is part of the "sockpp" C++ socket library. | ||
| 8 | -// | ||
| 9 | -// Copyright (c) 2021 Frank Pagliughi | ||
| 10 | -// All rights reserved. | ||
| 11 | -// | ||
| 12 | -// Redistribution and use in source and binary forms, with or without | ||
| 13 | -// modification, are permitted provided that the following conditions are | ||
| 14 | -// met: | ||
| 15 | -// | ||
| 16 | -// 1. Redistributions of source code must retain the above copyright notice, | ||
| 17 | -// this list of conditions and the following disclaimer. | ||
| 18 | -// | ||
| 19 | -// 2. Redistributions in binary form must reproduce the above copyright | ||
| 20 | -// notice, this list of conditions and the following disclaimer in the | ||
| 21 | -// documentation and/or other materials provided with the distribution. | ||
| 22 | -// | ||
| 23 | -// 3. Neither the name of the copyright holder nor the names of its | ||
| 24 | -// contributors may be used to endorse or promote products derived from this | ||
| 25 | -// software without specific prior written permission. | ||
| 26 | -// | ||
| 27 | -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
| 28 | -// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
| 29 | -// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 30 | -// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
| 31 | -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 32 | -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 33 | -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 34 | -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 35 | -// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 36 | -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 37 | -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 38 | -// -------------------------------------------------------------------------- | ||
| 39 | - | ||
| 40 | #include <iostream> | 1 | #include <iostream> |
| 41 | #include <iomanip> | 2 | #include <iomanip> |
| 42 | #include <string> | 3 | #include <string> |
| 43 | #include <chrono> | 4 | #include <chrono> |
| 44 | #include <thread> | 5 | #include <thread> |
| 45 | -#include "sockpp/can_socket.h" | ||
| 46 | -#include "sockpp/can_frame.h" | ||
| 47 | -#include "sockpp/version.h" | 6 | +#include "socket-cpp/can_socket.h" |
| 7 | +#include "socket-cpp/can_frame.h" | ||
| 8 | +#include "socket-cpp/version.h" | ||
| 48 | 9 | ||
| 49 | #include <net/if.h> | 10 | #include <net/if.h> |
| 50 | #include <sys/ioctl.h> | 11 | #include <sys/ioctl.h> |
| @@ -59,15 +20,15 @@ using sysclock = chrono::system_clock; | @@ -59,15 +20,15 @@ using sysclock = chrono::system_clock; | ||
| 59 | int main(int argc, char* argv[]) | 20 | int main(int argc, char* argv[]) |
| 60 | { | 21 | { |
| 61 | cout << "Sample SocketCAN writer for 'sockpp' " | 22 | cout << "Sample SocketCAN writer for 'sockpp' " |
| 62 | - << sockpp::SOCKPP_VERSION << endl; | 23 | + << osdev::components::socket-cpp::SOCKPP_VERSION << endl; |
| 63 | 24 | ||
| 64 | string canIface = (argc > 1) ? argv[1] : "can0"; | 25 | string canIface = (argc > 1) ? argv[1] : "can0"; |
| 65 | canid_t canID = (argc > 2) ? atoi(argv[2]) : 0x20; | 26 | canid_t canID = (argc > 2) ? atoi(argv[2]) : 0x20; |
| 66 | 27 | ||
| 67 | - sockpp::socket_initializer sockInit; | 28 | + osdev::components::socket-cpp::socket_initializer sockInit; |
| 68 | 29 | ||
| 69 | - sockpp::can_address addr(canIface); | ||
| 70 | - sockpp::can_socket sock(addr); | 30 | + osdev::components::socket-cpp::can_address addr(canIface); |
| 31 | + osdev::components::socket-cpp::can_socket sock(addr); | ||
| 71 | 32 | ||
| 72 | if (!sock) { | 33 | if (!sock) { |
| 73 | cerr << "Error binding to the CAN interface " << canIface << "\n\t" | 34 | cerr << "Error binding to the CAN interface " << canIface << "\n\t" |
| @@ -82,7 +43,7 @@ int main(int argc, char* argv[]) | @@ -82,7 +43,7 @@ int main(int argc, char* argv[]) | ||
| 82 | cout << setfill('0'); | 43 | cout << setfill('0'); |
| 83 | 44 | ||
| 84 | while (true) { | 45 | while (true) { |
| 85 | - sockpp::can_frame frame; | 46 | + osdev::components::socket-cpp::can_frame frame; |
| 86 | sock.recv(&frame); | 47 | sock.recv(&frame); |
| 87 | auto t = sock.last_frame_timestamp(); | 48 | auto t = sock.last_frame_timestamp(); |
| 88 | 49 |
examples/linux/cantime.cpp
| 1 | -// cantime.cpp | ||
| 2 | -// | ||
| 3 | -// Linux SoxketCAN writer example. | ||
| 4 | -// | ||
| 5 | -// This writes the 1-sec, 32-bit, Linux time_t value to the CAN bus each | ||
| 6 | -// time it ticks. This is a simple (though not overly precise) way to | ||
| 7 | -// synchronize the time for nodes on the bus | ||
| 8 | -// | ||
| 9 | -// -------------------------------------------------------------------------- | ||
| 10 | -// This file is part of the "sockpp" C++ socket library. | ||
| 11 | -// | ||
| 12 | -// Copyright (c) 2021 Frank Pagliughi | ||
| 13 | -// All rights reserved. | ||
| 14 | -// | ||
| 15 | -// Redistribution and use in source and binary forms, with or without | ||
| 16 | -// modification, are permitted provided that the following conditions are | ||
| 17 | -// met: | ||
| 18 | -// | ||
| 19 | -// 1. Redistributions of source code must retain the above copyright notice, | ||
| 20 | -// this list of conditions and the following disclaimer. | ||
| 21 | -// | ||
| 22 | -// 2. Redistributions in binary form must reproduce the above copyright | ||
| 23 | -// notice, this list of conditions and the following disclaimer in the | ||
| 24 | -// documentation and/or other materials provided with the distribution. | ||
| 25 | -// | ||
| 26 | -// 3. Neither the name of the copyright holder nor the names of its | ||
| 27 | -// contributors may be used to endorse or promote products derived from this | ||
| 28 | -// software without specific prior written permission. | ||
| 29 | -// | ||
| 30 | -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
| 31 | -// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
| 32 | -// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 33 | -// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
| 34 | -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 35 | -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 36 | -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 37 | -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 38 | -// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 39 | -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 40 | -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 41 | -// -------------------------------------------------------------------------- | ||
| 42 | - | ||
| 43 | #include <iostream> | 1 | #include <iostream> |
| 44 | #include <string> | 2 | #include <string> |
| 45 | #include <chrono> | 3 | #include <chrono> |
| 46 | #include <thread> | 4 | #include <thread> |
| 47 | -#include "sockpp/can_socket.h" | ||
| 48 | -#include "sockpp/can_frame.h" | ||
| 49 | -#include "sockpp/version.h" | 5 | +#include "socket-cpp/can_socket.h" |
| 6 | +#include "socket-cpp/can_frame.h" | ||
| 7 | +#include "socket-cpp/version.h" | ||
| 50 | 8 | ||
| 51 | #include <net/if.h> | 9 | #include <net/if.h> |
| 52 | #include <sys/ioctl.h> | 10 | #include <sys/ioctl.h> |
| @@ -60,16 +18,16 @@ using sysclock = chrono::system_clock; | @@ -60,16 +18,16 @@ using sysclock = chrono::system_clock; | ||
| 60 | 18 | ||
| 61 | int main(int argc, char* argv[]) | 19 | int main(int argc, char* argv[]) |
| 62 | { | 20 | { |
| 63 | - cout << "Sample SocketCAN writer for 'sockpp' " | ||
| 64 | - << sockpp::SOCKPP_VERSION << endl; | 21 | + cout << "Sample SocketCAN writer for 'Socket-Cpp' " |
| 22 | + << osdev::components::socket-cpp::SOCKPP_VERSION << endl; | ||
| 65 | 23 | ||
| 66 | string canIface = (argc > 1) ? argv[1] : "can0"; | 24 | string canIface = (argc > 1) ? argv[1] : "can0"; |
| 67 | canid_t canID = (argc > 2) ? atoi(argv[2]) : 0x20; | 25 | canid_t canID = (argc > 2) ? atoi(argv[2]) : 0x20; |
| 68 | 26 | ||
| 69 | - sockpp::socket_initializer sockInit; | 27 | + osdev::components::socket-cpp::socket_initializer sockInit; |
| 70 | 28 | ||
| 71 | - sockpp::can_address addr(canIface); | ||
| 72 | - sockpp::can_socket sock(addr); | 29 | + osdev::components::socket-cpp::can_address addr(canIface); |
| 30 | + osdev::components::socket-cpp::can_socket sock(addr); | ||
| 73 | 31 | ||
| 74 | if (!sock) { | 32 | if (!sock) { |
| 75 | cerr << "Error binding to the CAN interface " << canIface << "\n\t" | 33 | cerr << "Error binding to the CAN interface " << canIface << "\n\t" |
| @@ -90,7 +48,7 @@ int main(int argc, char* argv[]) | @@ -90,7 +48,7 @@ int main(int argc, char* argv[]) | ||
| 90 | // Write the time to the CAN bus as a 32-bit int | 48 | // Write the time to the CAN bus as a 32-bit int |
| 91 | auto nt = uint32_t(t); | 49 | auto nt = uint32_t(t); |
| 92 | 50 | ||
| 93 | - sockpp::can_frame frame { canID, &nt, sizeof(nt) }; | 51 | + osdev::components::socket-cpp::can_frame frame { canID, &nt, sizeof(nt) }; |
| 94 | sock.send(frame); | 52 | sock.send(frame); |
| 95 | } | 53 | } |
| 96 | 54 |
examples/tcp/tcp6echo.cpp
| 1 | -// tcpecho.cpp | ||
| 2 | -// | ||
| 3 | -// Simple TCP echo client | ||
| 4 | -// | ||
| 5 | -// -------------------------------------------------------------------------- | ||
| 6 | -// This file is part of the "sockpp" C++ socket library. | ||
| 7 | -// | ||
| 8 | -// Copyright (c) 2014-2017 Frank Pagliughi | ||
| 9 | -// All rights reserved. | ||
| 10 | -// | ||
| 11 | -// Redistribution and use in source and binary forms, with or without | ||
| 12 | -// modification, are permitted provided that the following conditions are | ||
| 13 | -// met: | ||
| 14 | -// | ||
| 15 | -// 1. Redistributions of source code must retain the above copyright notice, | ||
| 16 | -// this list of conditions and the following disclaimer. | ||
| 17 | -// | ||
| 18 | -// 2. Redistributions in binary form must reproduce the above copyright | ||
| 19 | -// notice, this list of conditions and the following disclaimer in the | ||
| 20 | -// documentation and/or other materials provided with the distribution. | ||
| 21 | -// | ||
| 22 | -// 3. Neither the name of the copyright holder nor the names of its | ||
| 23 | -// contributors may be used to endorse or promote products derived from this | ||
| 24 | -// software without specific prior written permission. | ||
| 25 | -// | ||
| 26 | -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
| 27 | -// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
| 28 | -// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 29 | -// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
| 30 | -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 31 | -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 32 | -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 33 | -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 34 | -// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 35 | -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 36 | -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 37 | -// -------------------------------------------------------------------------- | ||
| 38 | - | ||
| 39 | #include <iostream> | 1 | #include <iostream> |
| 40 | #include <string> | 2 | #include <string> |
| 41 | -#include "sockpp/tcp6_connector.h" | ||
| 42 | -#include "sockpp/version.h" | 3 | +#include "socket-cpp/tcp6_connector.h" |
| 4 | +#include "socket-cpp/version.h" | ||
| 43 | 5 | ||
| 44 | using namespace std; | 6 | using namespace std; |
| 45 | using namespace std::chrono; | 7 | using namespace std::chrono; |
| @@ -49,20 +11,20 @@ using namespace std::chrono; | @@ -49,20 +11,20 @@ using namespace std::chrono; | ||
| 49 | int main(int argc, char* argv[]) | 11 | int main(int argc, char* argv[]) |
| 50 | { | 12 | { |
| 51 | cout << "Sample IPv6 TCP echo client for 'sockpp' " | 13 | cout << "Sample IPv6 TCP echo client for 'sockpp' " |
| 52 | - << sockpp::SOCKPP_VERSION << '\n' << endl; | 14 | + << osdev::components::socket-cpp::SOCKPP_VERSION << '\n' << endl; |
| 53 | 15 | ||
| 54 | std::string host = (argc > 1) ? argv[1] : "::1"; | 16 | std::string host = (argc > 1) ? argv[1] : "::1"; |
| 55 | in_port_t port = (argc > 2) ? atoi(argv[2]) : 12345; | 17 | in_port_t port = (argc > 2) ? atoi(argv[2]) : 12345; |
| 56 | 18 | ||
| 57 | - sockpp::socket_initializer sockInit; | 19 | + osdev::components::socket-cpp::socket_initializer sockInit; |
| 58 | 20 | ||
| 59 | // Implicitly creates an inet6_address from {host,port} | 21 | // Implicitly creates an inet6_address from {host,port} |
| 60 | // and then tries the connection. | 22 | // and then tries the connection. |
| 61 | 23 | ||
| 62 | - sockpp::tcp6_connector conn({host, port}); | 24 | + osdev::components::socket-cpp::tcp6_connector conn({host, port}); |
| 63 | if (!conn) { | 25 | if (!conn) { |
| 64 | cerr << "Error connecting to server at " | 26 | cerr << "Error connecting to server at " |
| 65 | - << sockpp::inet6_address(host, port) | 27 | + << osdev::components::socket-cpp::inet6_address(host, port) |
| 66 | << "\n\t" << conn.last_error_str() << endl; | 28 | << "\n\t" << conn.last_error_str() << endl; |
| 67 | return 1; | 29 | return 1; |
| 68 | } | 30 | } |
examples/tcp/tcp6echosvr.cpp
| 1 | -// tcp6echosvr.cpp | ||
| 2 | -// | ||
| 3 | -// A multi-threaded TCP v6 echo server for sockpp library. | ||
| 4 | -// This is a simple thread-per-connection TCP server for IPv6. | ||
| 5 | -// | ||
| 6 | -// USAGE: | ||
| 7 | -// tcp6echosvr [port] | ||
| 8 | -// | ||
| 9 | -// -------------------------------------------------------------------------- | ||
| 10 | -// This file is part of the "sockpp" C++ socket library. | ||
| 11 | -// | ||
| 12 | -// Copyright (c) 2019 Frank Pagliughi | ||
| 13 | -// All rights reserved. | ||
| 14 | -// | ||
| 15 | -// Redistribution and use in source and binary forms, with or without | ||
| 16 | -// modification, are permitted provided that the following conditions are | ||
| 17 | -// met: | ||
| 18 | -// | ||
| 19 | -// 1. Redistributions of source code must retain the above copyright notice, | ||
| 20 | -// this list of conditions and the following disclaimer. | ||
| 21 | -// | ||
| 22 | -// 2. Redistributions in binary form must reproduce the above copyright | ||
| 23 | -// notice, this list of conditions and the following disclaimer in the | ||
| 24 | -// documentation and/or other materials provided with the distribution. | ||
| 25 | -// | ||
| 26 | -// 3. Neither the name of the copyright holder nor the names of its | ||
| 27 | -// contributors may be used to endorse or promote products derived from this | ||
| 28 | -// software without specific prior written permission. | ||
| 29 | -// | ||
| 30 | -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
| 31 | -// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
| 32 | -// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 33 | -// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
| 34 | -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 35 | -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 36 | -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 37 | -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 38 | -// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 39 | -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 40 | -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 41 | -// -------------------------------------------------------------------------- | ||
| 42 | - | ||
| 43 | #include <iostream> | 1 | #include <iostream> |
| 44 | #include <thread> | 2 | #include <thread> |
| 45 | -#include "sockpp/tcp6_acceptor.h" | ||
| 46 | -#include "sockpp/version.h" | 3 | +#include "socket-cpp/tcp6_acceptor.h" |
| 4 | +#include "socket-cpp/version.h" | ||
| 47 | 5 | ||
| 48 | using namespace std; | 6 | using namespace std; |
| 49 | 7 | ||
| @@ -52,7 +10,7 @@ using namespace std; | @@ -52,7 +10,7 @@ using namespace std; | ||
| 52 | // Ownership of the socket object is transferred to the thread, so when this | 10 | // Ownership of the socket object is transferred to the thread, so when this |
| 53 | // function exits, the socket is automatically closed. | 11 | // function exits, the socket is automatically closed. |
| 54 | 12 | ||
| 55 | -void run_echo(sockpp::tcp6_socket sock) | 13 | +void run_echo(osdev::components::socket-cpp::tcp6_socket sock) |
| 56 | { | 14 | { |
| 57 | ssize_t n; | 15 | ssize_t n; |
| 58 | char buf[512]; | 16 | char buf[512]; |
| @@ -71,12 +29,12 @@ void run_echo(sockpp::tcp6_socket sock) | @@ -71,12 +29,12 @@ void run_echo(sockpp::tcp6_socket sock) | ||
| 71 | int main(int argc, char* argv[]) | 29 | int main(int argc, char* argv[]) |
| 72 | { | 30 | { |
| 73 | cout << "Sample IPv6 TCP echo server for 'sockpp' " | 31 | cout << "Sample IPv6 TCP echo server for 'sockpp' " |
| 74 | - << sockpp::SOCKPP_VERSION << '\n' << endl; | 32 | + << osdev::components::socket-cpp::SOCKPP_VERSION << '\n' << endl; |
| 75 | 33 | ||
| 76 | in_port_t port = (argc > 1) ? atoi(argv[1]) : 12345; | 34 | in_port_t port = (argc > 1) ? atoi(argv[1]) : 12345; |
| 77 | 35 | ||
| 78 | - sockpp::socket_initializer sockInit; | ||
| 79 | - sockpp::tcp6_acceptor acc(port); | 36 | + osdev::components::socket-cpp::socket_initializer sockInit; |
| 37 | + osdev::components::socket-cpp::tcp6_acceptor acc(port); | ||
| 80 | 38 | ||
| 81 | if (!acc) { | 39 | if (!acc) { |
| 82 | cerr << "Error creating the acceptor: " << acc.last_error_str() << endl; | 40 | cerr << "Error creating the acceptor: " << acc.last_error_str() << endl; |
| @@ -85,10 +43,10 @@ int main(int argc, char* argv[]) | @@ -85,10 +43,10 @@ int main(int argc, char* argv[]) | ||
| 85 | cout << "Awaiting connections on port " << port << "..." << endl; | 43 | cout << "Awaiting connections on port " << port << "..." << endl; |
| 86 | 44 | ||
| 87 | while (true) { | 45 | while (true) { |
| 88 | - sockpp::inet6_address peer; | 46 | + osdev::components::socket-cpp::inet6_address peer; |
| 89 | 47 | ||
| 90 | // Accept a new client connection | 48 | // Accept a new client connection |
| 91 | - sockpp::tcp6_socket sock = acc.accept(&peer); | 49 | + osdev::components::socket-cpp::tcp6_socket sock = acc.accept(&peer); |
| 92 | cout << "Received a connection request from " << peer << endl; | 50 | cout << "Received a connection request from " << peer << endl; |
| 93 | 51 | ||
| 94 | if (!sock) { | 52 | if (!sock) { |
examples/tcp/tcpecho.cpp
| 1 | -// tcpecho.cpp | ||
| 2 | -// | ||
| 3 | -// Simple TCP echo client | ||
| 4 | -// | ||
| 5 | -// -------------------------------------------------------------------------- | ||
| 6 | -// This file is part of the "sockpp" C++ socket library. | ||
| 7 | -// | ||
| 8 | -// Copyright (c) 2014-2017 Frank Pagliughi | ||
| 9 | -// All rights reserved. | ||
| 10 | -// | ||
| 11 | -// Redistribution and use in source and binary forms, with or without | ||
| 12 | -// modification, are permitted provided that the following conditions are | ||
| 13 | -// met: | ||
| 14 | -// | ||
| 15 | -// 1. Redistributions of source code must retain the above copyright notice, | ||
| 16 | -// this list of conditions and the following disclaimer. | ||
| 17 | -// | ||
| 18 | -// 2. Redistributions in binary form must reproduce the above copyright | ||
| 19 | -// notice, this list of conditions and the following disclaimer in the | ||
| 20 | -// documentation and/or other materials provided with the distribution. | ||
| 21 | -// | ||
| 22 | -// 3. Neither the name of the copyright holder nor the names of its | ||
| 23 | -// contributors may be used to endorse or promote products derived from this | ||
| 24 | -// software without specific prior written permission. | ||
| 25 | -// | ||
| 26 | -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
| 27 | -// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
| 28 | -// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 29 | -// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
| 30 | -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 31 | -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 32 | -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 33 | -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 34 | -// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 35 | -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 36 | -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 37 | -// -------------------------------------------------------------------------- | ||
| 38 | - | ||
| 39 | #include <iostream> | 1 | #include <iostream> |
| 40 | #include <string> | 2 | #include <string> |
| 41 | -#include "sockpp/tcp_connector.h" | ||
| 42 | -#include "sockpp/version.h" | 3 | +#include "socket-cpp/tcp_connector.h" |
| 4 | +#include "socket-cpp/version.h" | ||
| 43 | 5 | ||
| 44 | using namespace std; | 6 | using namespace std; |
| 45 | using namespace std::chrono; | 7 | using namespace std::chrono; |
| @@ -47,20 +9,20 @@ using namespace std::chrono; | @@ -47,20 +9,20 @@ using namespace std::chrono; | ||
| 47 | int main(int argc, char* argv[]) | 9 | int main(int argc, char* argv[]) |
| 48 | { | 10 | { |
| 49 | cout << "Sample TCP echo client for 'sockpp' " | 11 | cout << "Sample TCP echo client for 'sockpp' " |
| 50 | - << sockpp::SOCKPP_VERSION << '\n' << endl; | 12 | + << osdev::components::socket-cpp::SOCKPP_VERSION << '\n' << endl; |
| 51 | 13 | ||
| 52 | string host = (argc > 1) ? argv[1] : "localhost"; | 14 | string host = (argc > 1) ? argv[1] : "localhost"; |
| 53 | in_port_t port = (argc > 2) ? atoi(argv[2]) : 12345; | 15 | in_port_t port = (argc > 2) ? atoi(argv[2]) : 12345; |
| 54 | 16 | ||
| 55 | - sockpp::socket_initializer sockInit; | 17 | + osdev::components::socket-cpp::socket_initializer sockInit; |
| 56 | 18 | ||
| 57 | // Implicitly creates an inet_address from {host,port} | 19 | // Implicitly creates an inet_address from {host,port} |
| 58 | // and then tries the connection. | 20 | // and then tries the connection. |
| 59 | 21 | ||
| 60 | - sockpp::tcp_connector conn({host, port}); | 22 | + osdev::components::socket-cpp::tcp_connector conn({host, port}); |
| 61 | if (!conn) { | 23 | if (!conn) { |
| 62 | cerr << "Error connecting to server at " | 24 | cerr << "Error connecting to server at " |
| 63 | - << sockpp::inet_address(host, port) | 25 | + << osdev::components::socket-cpp::inet_address(host, port) |
| 64 | << "\n\t" << conn.last_error_str() << endl; | 26 | << "\n\t" << conn.last_error_str() << endl; |
| 65 | return 1; | 27 | return 1; |
| 66 | } | 28 | } |
examples/tcp/tcpechomt.cpp
| 1 | -// tcpechomt.cpp | ||
| 2 | -// | ||
| 3 | -// TCP echo client that uses separate read and write threads. | ||
| 4 | -// | ||
| 5 | -// -------------------------------------------------------------------------- | ||
| 6 | -// This file is part of the "sockpp" C++ socket library. | ||
| 7 | -// | ||
| 8 | -// Copyright (c) 2014-2017 Frank Pagliughi | ||
| 9 | -// All rights reserved. | ||
| 10 | -// | ||
| 11 | -// Redistribution and use in source and binary forms, with or without | ||
| 12 | -// modification, are permitted provided that the following conditions are | ||
| 13 | -// met: | ||
| 14 | -// | ||
| 15 | -// 1. Redistributions of source code must retain the above copyright notice, | ||
| 16 | -// this list of conditions and the following disclaimer. | ||
| 17 | -// | ||
| 18 | -// 2. Redistributions in binary form must reproduce the above copyright | ||
| 19 | -// notice, this list of conditions and the following disclaimer in the | ||
| 20 | -// documentation and/or other materials provided with the distribution. | ||
| 21 | -// | ||
| 22 | -// 3. Neither the name of the copyright holder nor the names of its | ||
| 23 | -// contributors may be used to endorse or promote products derived from this | ||
| 24 | -// software without specific prior written permission. | ||
| 25 | -// | ||
| 26 | -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
| 27 | -// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
| 28 | -// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 29 | -// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
| 30 | -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 31 | -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 32 | -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 33 | -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 34 | -// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 35 | -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 36 | -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 37 | -// -------------------------------------------------------------------------- | ||
| 38 | - | ||
| 39 | #include <iostream> | 1 | #include <iostream> |
| 40 | #include <string> | 2 | #include <string> |
| 41 | #include <thread> | 3 | #include <thread> |
| 42 | -#include "sockpp/tcp_connector.h" | ||
| 43 | -#include "sockpp/version.h" | 4 | +#include "socket-cpp/tcp_connector.h" |
| 5 | +#include "socket-cpp/version.h" | ||
| 44 | 6 | ||
| 45 | using namespace std; | 7 | using namespace std; |
| 46 | 8 | ||
| @@ -49,7 +11,7 @@ using namespace std; | @@ -49,7 +11,7 @@ using namespace std; | ||
| 49 | // server and writing them to the console. When the main (write) thread | 11 | // server and writing them to the console. When the main (write) thread |
| 50 | // shuts down the socket, we exit. | 12 | // shuts down the socket, we exit. |
| 51 | 13 | ||
| 52 | -void read_thr(sockpp::tcp_socket rdSock) | 14 | +void read_thr(osdev::components::socket-cpp::tcp_socket rdSock) |
| 53 | { | 15 | { |
| 54 | char buf[512]; | 16 | char buf[512]; |
| 55 | ssize_t n; | 17 | ssize_t n; |
| @@ -71,20 +33,20 @@ void read_thr(sockpp::tcp_socket rdSock) | @@ -71,20 +33,20 @@ void read_thr(sockpp::tcp_socket rdSock) | ||
| 71 | int main(int argc, char* argv[]) | 33 | int main(int argc, char* argv[]) |
| 72 | { | 34 | { |
| 73 | cout << "Sample multi-threaded TCP echo client for 'sockpp' " | 35 | cout << "Sample multi-threaded TCP echo client for 'sockpp' " |
| 74 | - << sockpp::SOCKPP_VERSION << '\n' << endl; | 36 | + << osdev::components::socket-cpp::SOCKPP_VERSION << '\n' << endl; |
| 75 | 37 | ||
| 76 | string host = (argc > 1) ? argv[1] : "localhost"; | 38 | string host = (argc > 1) ? argv[1] : "localhost"; |
| 77 | in_port_t port = (argc > 2) ? atoi(argv[2]) : 12345; | 39 | in_port_t port = (argc > 2) ? atoi(argv[2]) : 12345; |
| 78 | 40 | ||
| 79 | - sockpp::socket_initializer sockInit; | 41 | + osdev::components::socket-cpp::socket_initializer sockInit; |
| 80 | 42 | ||
| 81 | // Implicitly creates an inet_address from {host,port} | 43 | // Implicitly creates an inet_address from {host,port} |
| 82 | // and then tries the connection. | 44 | // and then tries the connection. |
| 83 | 45 | ||
| 84 | - sockpp::tcp_connector conn({host, port}); | 46 | + osdev::components::socket-cpp::tcp_connector conn({host, port}); |
| 85 | if (!conn) { | 47 | if (!conn) { |
| 86 | cerr << "Error connecting to server at " | 48 | cerr << "Error connecting to server at " |
| 87 | - << sockpp::inet_address(host, port) | 49 | + << osdev::components::socket-cpp::inet_address(host, port) |
| 88 | << "\n\t" << conn.last_error_str() << endl; | 50 | << "\n\t" << conn.last_error_str() << endl; |
| 89 | return 1; | 51 | return 1; |
| 90 | } | 52 | } |
examples/tcp/tcpechosvr.cpp
| 1 | -// tcpechosvr.cpp | ||
| 2 | -// | ||
| 3 | -// A multi-threaded TCP echo server for sockpp library. | ||
| 4 | -// This is a simple thread-per-connection TCP server. | ||
| 5 | -// | ||
| 6 | -// USAGE: | ||
| 7 | -// tcpechosvr [port] | ||
| 8 | -// | ||
| 9 | -// -------------------------------------------------------------------------- | ||
| 10 | -// This file is part of the "sockpp" C++ socket library. | ||
| 11 | -// | ||
| 12 | -// Copyright (c) 2014-2017 Frank Pagliughi | ||
| 13 | -// All rights reserved. | ||
| 14 | -// | ||
| 15 | -// Redistribution and use in source and binary forms, with or without | ||
| 16 | -// modification, are permitted provided that the following conditions are | ||
| 17 | -// met: | ||
| 18 | -// | ||
| 19 | -// 1. Redistributions of source code must retain the above copyright notice, | ||
| 20 | -// this list of conditions and the following disclaimer. | ||
| 21 | -// | ||
| 22 | -// 2. Redistributions in binary form must reproduce the above copyright | ||
| 23 | -// notice, this list of conditions and the following disclaimer in the | ||
| 24 | -// documentation and/or other materials provided with the distribution. | ||
| 25 | -// | ||
| 26 | -// 3. Neither the name of the copyright holder nor the names of its | ||
| 27 | -// contributors may be used to endorse or promote products derived from this | ||
| 28 | -// software without specific prior written permission. | ||
| 29 | -// | ||
| 30 | -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
| 31 | -// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
| 32 | -// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 33 | -// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
| 34 | -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 35 | -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 36 | -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 37 | -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 38 | -// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 39 | -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 40 | -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 41 | -// -------------------------------------------------------------------------- | ||
| 42 | - | ||
| 43 | #include <iostream> | 1 | #include <iostream> |
| 44 | #include <thread> | 2 | #include <thread> |
| 45 | -#include "sockpp/tcp_acceptor.h" | ||
| 46 | -#include "sockpp/version.h" | 3 | +#include "socket-cpp/tcp_acceptor.h" |
| 4 | +#include "socket-cpp/version.h" | ||
| 47 | 5 | ||
| 48 | using namespace std; | 6 | using namespace std; |
| 49 | 7 | ||
| @@ -52,7 +10,7 @@ using namespace std; | @@ -52,7 +10,7 @@ using namespace std; | ||
| 52 | // Ownership of the socket object is transferred to the thread, so when this | 10 | // Ownership of the socket object is transferred to the thread, so when this |
| 53 | // function exits, the socket is automatically closed. | 11 | // function exits, the socket is automatically closed. |
| 54 | 12 | ||
| 55 | -void run_echo(sockpp::tcp_socket sock) | 13 | +void run_echo(osdev::components::socket-cpp::tcp_socket sock) |
| 56 | { | 14 | { |
| 57 | ssize_t n; | 15 | ssize_t n; |
| 58 | char buf[512]; | 16 | char buf[512]; |
| @@ -71,13 +29,13 @@ void run_echo(sockpp::tcp_socket sock) | @@ -71,13 +29,13 @@ void run_echo(sockpp::tcp_socket sock) | ||
| 71 | int main(int argc, char* argv[]) | 29 | int main(int argc, char* argv[]) |
| 72 | { | 30 | { |
| 73 | cout << "Sample TCP echo server for 'sockpp' " | 31 | cout << "Sample TCP echo server for 'sockpp' " |
| 74 | - << sockpp::SOCKPP_VERSION << '\n' << endl; | 32 | + << osdev::components::socket-cpp::SOCKPP_VERSION << '\n' << endl; |
| 75 | 33 | ||
| 76 | in_port_t port = (argc > 1) ? atoi(argv[1]) : 12345; | 34 | in_port_t port = (argc > 1) ? atoi(argv[1]) : 12345; |
| 77 | 35 | ||
| 78 | - sockpp::socket_initializer sockInit; | 36 | + osdev::components::socket-cpp::socket_initializer sockInit; |
| 79 | 37 | ||
| 80 | - sockpp::tcp_acceptor acc(port); | 38 | + osdev::components::socket-cpp::tcp_acceptor acc(port); |
| 81 | 39 | ||
| 82 | if (!acc) { | 40 | if (!acc) { |
| 83 | cerr << "Error creating the acceptor: " << acc.last_error_str() << endl; | 41 | cerr << "Error creating the acceptor: " << acc.last_error_str() << endl; |
| @@ -87,10 +45,10 @@ int main(int argc, char* argv[]) | @@ -87,10 +45,10 @@ int main(int argc, char* argv[]) | ||
| 87 | cout << "Awaiting connections on port " << port << "..." << endl; | 45 | cout << "Awaiting connections on port " << port << "..." << endl; |
| 88 | 46 | ||
| 89 | while (true) { | 47 | while (true) { |
| 90 | - sockpp::inet_address peer; | 48 | + osdev::components::socket-cpp::inet_address peer; |
| 91 | 49 | ||
| 92 | // Accept a new client connection | 50 | // Accept a new client connection |
| 93 | - sockpp::tcp_socket sock = acc.accept(&peer); | 51 | + osdev::components::socket-cpp::tcp_socket sock = acc.accept(&peer); |
| 94 | cout << "Received a connection request from " << peer << endl; | 52 | cout << "Received a connection request from " << peer << endl; |
| 95 | 53 | ||
| 96 | if (!sock) { | 54 | if (!sock) { |
examples/tcp/tcpechotest.cpp
| 1 | -// tcpechotest.cpp | ||
| 2 | -// | ||
| 3 | -// TCP echo timing client. | ||
| 4 | -// | ||
| 5 | -// -------------------------------------------------------------------------- | ||
| 6 | -// This file is part of the "sockpp" C++ socket library. | ||
| 7 | -// | ||
| 8 | -// Copyright (c) 2020 Frank Pagliughi | ||
| 9 | -// All rights reserved. | ||
| 10 | -// | ||
| 11 | -// Redistribution and use in source and binary forms, with or without | ||
| 12 | -// modification, are permitted provided that the following conditions are | ||
| 13 | -// met: | ||
| 14 | -// | ||
| 15 | -// 1. Redistributions of source code must retain the above copyright notice, | ||
| 16 | -// this list of conditions and the following disclaimer. | ||
| 17 | -// | ||
| 18 | -// 2. Redistributions in binary form must reproduce the above copyright | ||
| 19 | -// notice, this list of conditions and the following disclaimer in the | ||
| 20 | -// documentation and/or other materials provided with the distribution. | ||
| 21 | -// | ||
| 22 | -// 3. Neither the name of the copyright holder nor the names of its | ||
| 23 | -// contributors may be used to endorse or promote products derived from this | ||
| 24 | -// software without specific prior written permission. | ||
| 25 | -// | ||
| 26 | -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
| 27 | -// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
| 28 | -// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 29 | -// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
| 30 | -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 31 | -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 32 | -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 33 | -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 34 | -// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 35 | -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 36 | -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 37 | -// -------------------------------------------------------------------------- | ||
| 38 | - | ||
| 39 | #include <iostream> | 1 | #include <iostream> |
| 40 | #include <string> | 2 | #include <string> |
| 41 | #include <chrono> | 3 | #include <chrono> |
| 42 | #include <random> | 4 | #include <random> |
| 43 | -#include "sockpp/tcp_connector.h" | ||
| 44 | -#include "sockpp/version.h" | 5 | +#include "socket-cpp/tcp_connector.h" |
| 6 | +#include "socket-cpp/version.h" | ||
| 45 | 7 | ||
| 46 | using namespace std; | 8 | using namespace std; |
| 47 | using namespace std::chrono; | 9 | using namespace std::chrono; |
| @@ -56,7 +18,7 @@ using fpsec = std::chrono::duration<double, std::chrono::seconds::period>; | @@ -56,7 +18,7 @@ using fpsec = std::chrono::duration<double, std::chrono::seconds::period>; | ||
| 56 | int main(int argc, char* argv[]) | 18 | int main(int argc, char* argv[]) |
| 57 | { | 19 | { |
| 58 | cout << "Unix-domain echo timing test client for 'sockpp' " | 20 | cout << "Unix-domain echo timing test client for 'sockpp' " |
| 59 | - << sockpp::SOCKPP_VERSION << '\n' << endl; | 21 | + << osdev::components::socket-cpp::SOCKPP_VERSION << '\n' << endl; |
| 60 | 22 | ||
| 61 | string host = (argc > 1) ? argv[1] : "localhost"; | 23 | string host = (argc > 1) ? argv[1] : "localhost"; |
| 62 | in_port_t port = (argc > 2) ? atoi(argv[2]) : 12345; | 24 | in_port_t port = (argc > 2) ? atoi(argv[2]) : 12345; |
| @@ -64,15 +26,15 @@ int main(int argc, char* argv[]) | @@ -64,15 +26,15 @@ int main(int argc, char* argv[]) | ||
| 64 | size_t n = (argc > 3) ? size_t(atoll(argv[3])) : DFLT_N; | 26 | size_t n = (argc > 3) ? size_t(atoll(argv[3])) : DFLT_N; |
| 65 | size_t sz = (argc > 4) ? size_t(atoll(argv[4])) : DFLT_SZ; | 27 | size_t sz = (argc > 4) ? size_t(atoll(argv[4])) : DFLT_SZ; |
| 66 | 28 | ||
| 67 | - sockpp::socket_initializer sockInit; | 29 | + osdev::components::socket-cpp::socket_initializer sockInit; |
| 68 | 30 | ||
| 69 | auto t_start = high_resolution_clock::now(); | 31 | auto t_start = high_resolution_clock::now(); |
| 70 | 32 | ||
| 71 | 33 | ||
| 72 | - sockpp::tcp_connector conn({host, port}); | 34 | + osdev::components::socket-cpp::tcp_connector conn({host, port}); |
| 73 | if (!conn) { | 35 | if (!conn) { |
| 74 | cerr << "Error connecting to server at " | 36 | cerr << "Error connecting to server at " |
| 75 | - << sockpp::inet_address(host, port) | 37 | + << osdev::components::socket-cpp::inet_address(host, port) |
| 76 | << "\n\t" << conn.last_error_str() << endl; | 38 | << "\n\t" << conn.last_error_str() << endl; |
| 77 | return 1; | 39 | return 1; |
| 78 | } | 40 | } |
examples/udp/udp6echo.cpp
| 1 | -// udp6echo.cpp | ||
| 2 | -// | ||
| 3 | -// Simple UDP v6 echo client | ||
| 4 | -// | ||
| 5 | -// -------------------------------------------------------------------------- | ||
| 6 | -// This file is part of the "sockpp" C++ socket library. | ||
| 7 | -// | ||
| 8 | -// Copyright (c) 2019 Frank Pagliughi | ||
| 9 | -// All rights reserved. | ||
| 10 | -// | ||
| 11 | -// Redistribution and use in source and binary forms, with or without | ||
| 12 | -// modification, are permitted provided that the following conditions are | ||
| 13 | -// met: | ||
| 14 | -// | ||
| 15 | -// 1. Redistributions of source code must retain the above copyright notice, | ||
| 16 | -// this list of conditions and the following disclaimer. | ||
| 17 | -// | ||
| 18 | -// 2. Redistributions in binary form must reproduce the above copyright | ||
| 19 | -// notice, this list of conditions and the following disclaimer in the | ||
| 20 | -// documentation and/or other materials provided with the distribution. | ||
| 21 | -// | ||
| 22 | -// 3. Neither the name of the copyright holder nor the names of its | ||
| 23 | -// contributors may be used to endorse or promote products derived from this | ||
| 24 | -// software without specific prior written permission. | ||
| 25 | -// | ||
| 26 | -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
| 27 | -// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
| 28 | -// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 29 | -// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
| 30 | -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 31 | -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 32 | -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 33 | -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 34 | -// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 35 | -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 36 | -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 37 | -// -------------------------------------------------------------------------- | ||
| 38 | - | ||
| 39 | #include <iostream> | 1 | #include <iostream> |
| 40 | #include <string> | 2 | #include <string> |
| 41 | #include "sockpp/udp6_socket.h" | 3 | #include "sockpp/udp6_socket.h" |
| @@ -48,16 +10,16 @@ using namespace std; | @@ -48,16 +10,16 @@ using namespace std; | ||
| 48 | int main(int argc, char* argv[]) | 10 | int main(int argc, char* argv[]) |
| 49 | { | 11 | { |
| 50 | cout << "Sample IPv6 UDP echo client for 'sockpp' " | 12 | cout << "Sample IPv6 UDP echo client for 'sockpp' " |
| 51 | - << sockpp::SOCKPP_VERSION << '\n' << endl; | 13 | + << osdev::components::socket-cpp::SOCKPP_VERSION << '\n' << endl; |
| 52 | 14 | ||
| 53 | string host = (argc > 1) ? argv[1] : "localhost"; | 15 | string host = (argc > 1) ? argv[1] : "localhost"; |
| 54 | in_port_t port = (argc > 2) ? atoi(argv[2]) : 12345; | 16 | in_port_t port = (argc > 2) ? atoi(argv[2]) : 12345; |
| 55 | 17 | ||
| 56 | - sockpp::socket_initializer sockInit; | 18 | + osdev::components::socket-cpp::socket_initializer sockInit; |
| 57 | 19 | ||
| 58 | - sockpp::udp6_socket sock; | 20 | + osdev::components::socket-cpp::udp6_socket sock; |
| 59 | 21 | ||
| 60 | - if (!sock.connect(sockpp::inet6_address(host, port))) { | 22 | + if (!sock.connect(osdev::components::socket-cpp::inet6_address(host, port))) { |
| 61 | cerr << "Error connecting to server at " << host << ":" << port | 23 | cerr << "Error connecting to server at " << host << ":" << port |
| 62 | << "\n\t" << sock.last_error_str() << endl; | 24 | << "\n\t" << sock.last_error_str() << endl; |
| 63 | return 1; | 25 | return 1; |
examples/udp/udpecho.cpp
| 1 | -// udpecho.cpp | ||
| 2 | -// | ||
| 3 | -// Simple UDP v4 echo client | ||
| 4 | -// | ||
| 5 | -// -------------------------------------------------------------------------- | ||
| 6 | -// This file is part of the "sockpp" C++ socket library. | ||
| 7 | -// | ||
| 8 | -// Copyright (c) 2019 Frank Pagliughi | ||
| 9 | -// All rights reserved. | ||
| 10 | -// | ||
| 11 | -// Redistribution and use in source and binary forms, with or without | ||
| 12 | -// modification, are permitted provided that the following conditions are | ||
| 13 | -// met: | ||
| 14 | -// | ||
| 15 | -// 1. Redistributions of source code must retain the above copyright notice, | ||
| 16 | -// this list of conditions and the following disclaimer. | ||
| 17 | -// | ||
| 18 | -// 2. Redistributions in binary form must reproduce the above copyright | ||
| 19 | -// notice, this list of conditions and the following disclaimer in the | ||
| 20 | -// documentation and/or other materials provided with the distribution. | ||
| 21 | -// | ||
| 22 | -// 3. Neither the name of the copyright holder nor the names of its | ||
| 23 | -// contributors may be used to endorse or promote products derived from this | ||
| 24 | -// software without specific prior written permission. | ||
| 25 | -// | ||
| 26 | -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
| 27 | -// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
| 28 | -// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 29 | -// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
| 30 | -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 31 | -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 32 | -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 33 | -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 34 | -// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 35 | -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 36 | -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 37 | -// -------------------------------------------------------------------------- | ||
| 38 | - | ||
| 39 | #include <iostream> | 1 | #include <iostream> |
| 40 | #include <string> | 2 | #include <string> |
| 41 | #include "sockpp/udp_socket.h" | 3 | #include "sockpp/udp_socket.h" |
| @@ -48,16 +10,16 @@ using namespace std; | @@ -48,16 +10,16 @@ using namespace std; | ||
| 48 | int main(int argc, char* argv[]) | 10 | int main(int argc, char* argv[]) |
| 49 | { | 11 | { |
| 50 | cout << "Sample UDP echo client for 'sockpp' " | 12 | cout << "Sample UDP echo client for 'sockpp' " |
| 51 | - << sockpp::SOCKPP_VERSION << '\n' << endl; | 13 | + << osdev::components::socket-cpp::SOCKPP_VERSION << '\n' << endl; |
| 52 | 14 | ||
| 53 | string host = (argc > 1) ? argv[1] : "localhost"; | 15 | string host = (argc > 1) ? argv[1] : "localhost"; |
| 54 | in_port_t port = (argc > 2) ? atoi(argv[2]) : 12345; | 16 | in_port_t port = (argc > 2) ? atoi(argv[2]) : 12345; |
| 55 | 17 | ||
| 56 | - sockpp::socket_initializer sockInit; | 18 | + osdev::components::socket-cpp::socket_initializer sockInit; |
| 57 | 19 | ||
| 58 | - sockpp::udp_socket sock; | 20 | + osdev::components::socket-cpp::udp_socket sock; |
| 59 | 21 | ||
| 60 | - if (!sock.connect(sockpp::inet_address(host, port))) { | 22 | + if (!sock.connect(osdev::components::socket-cpp::inet_address(host, port))) { |
| 61 | cerr << "Error connecting to server at " << host << ":" << port | 23 | cerr << "Error connecting to server at " << host << ":" << port |
| 62 | << "\n\t" << sock.last_error_str() << endl; | 24 | << "\n\t" << sock.last_error_str() << endl; |
| 63 | return 1; | 25 | return 1; |
examples/udp/udpechosvr.cpp
| 1 | -// udpechosvr.cpp | ||
| 2 | -// | ||
| 3 | -// A simple multi-threaded TCP/IP UDP echo server for sockpp library. | ||
| 4 | -// | ||
| 5 | -// This runs a UDP echo server for both IPv4 and IPv6, each in a separate | ||
| 6 | -// thread. They both use the same port number, either as provided by the user | ||
| 7 | -// on the command line, or defaulting to 12345. | ||
| 8 | -// | ||
| 9 | -// USAGE: | ||
| 10 | -// uspechosvr [port] | ||
| 11 | -// | ||
| 12 | -// You can test with a netcat client, like: | ||
| 13 | -// $ nc -u localhost 12345 # IPv4 | ||
| 14 | -// $ nc -6u localhost 12345 # IPv6 | ||
| 15 | -// | ||
| 16 | -// -------------------------------------------------------------------------- | ||
| 17 | -// This file is part of the "sockpp" C++ socket library. | ||
| 18 | -// | ||
| 19 | -// Copyright (c) 2019 Frank Pagliughi | ||
| 20 | -// All rights reserved. | ||
| 21 | -// | ||
| 22 | -// Redistribution and use in source and binary forms, with or without | ||
| 23 | -// modification, are permitted provided that the following conditions are | ||
| 24 | -// met: | ||
| 25 | -// | ||
| 26 | -// 1. Redistributions of source code must retain the above copyright notice, | ||
| 27 | -// this list of conditions and the following disclaimer. | ||
| 28 | -// | ||
| 29 | -// 2. Redistributions in binary form must reproduce the above copyright | ||
| 30 | -// notice, this list of conditions and the following disclaimer in the | ||
| 31 | -// documentation and/or other materials provided with the distribution. | ||
| 32 | -// | ||
| 33 | -// 3. Neither the name of the copyright holder nor the names of its | ||
| 34 | -// contributors may be used to endorse or promote products derived from this | ||
| 35 | -// software without specific prior written permission. | ||
| 36 | -// | ||
| 37 | -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
| 38 | -// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
| 39 | -// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 40 | -// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
| 41 | -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 42 | -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 43 | -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 44 | -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 45 | -// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 46 | -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 47 | -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | -// -------------------------------------------------------------------------- | ||
| 49 | - | ||
| 50 | #include <iostream> | 1 | #include <iostream> |
| 51 | #include <thread> | 2 | #include <thread> |
| 52 | #include "sockpp/udp_socket.h" | 3 | #include "sockpp/udp_socket.h" |
| @@ -82,36 +33,36 @@ void run_echo(UDPSOCK sock) | @@ -82,36 +33,36 @@ void run_echo(UDPSOCK sock) | ||
| 82 | int main(int argc, char* argv[]) | 33 | int main(int argc, char* argv[]) |
| 83 | { | 34 | { |
| 84 | cout << "Sample UDP echo server for 'sockpp' " | 35 | cout << "Sample UDP echo server for 'sockpp' " |
| 85 | - << sockpp::SOCKPP_VERSION << '\n' << endl; | 36 | + << osdev::components::socket-cpp::SOCKPP_VERSION << '\n' << endl; |
| 86 | 37 | ||
| 87 | in_port_t port = (argc > 1) ? atoi(argv[1]) : 12345; | 38 | in_port_t port = (argc > 1) ? atoi(argv[1]) : 12345; |
| 88 | 39 | ||
| 89 | - sockpp::socket_initializer sockInit; | 40 | + osdev::components::socket-cpp::socket_initializer sockInit; |
| 90 | 41 | ||
| 91 | - sockpp::udp_socket udpsock; | 42 | + osdev::components::socket-cpp::udp_socket udpsock; |
| 92 | if (!udpsock) { | 43 | if (!udpsock) { |
| 93 | cerr << "Error creating the UDP v4 socket: " << udpsock.last_error_str() << endl; | 44 | cerr << "Error creating the UDP v4 socket: " << udpsock.last_error_str() << endl; |
| 94 | return 1; | 45 | return 1; |
| 95 | } | 46 | } |
| 96 | 47 | ||
| 97 | - if (!udpsock.bind(sockpp::inet_address("localhost", port))) { | 48 | + if (!udpsock.bind(osdev::components::socket-cpp::inet_address("localhost", port))) { |
| 98 | cerr << "Error binding the UDP v4 socket: " << udpsock.last_error_str() << endl; | 49 | cerr << "Error binding the UDP v4 socket: " << udpsock.last_error_str() << endl; |
| 99 | return 1; | 50 | return 1; |
| 100 | } | 51 | } |
| 101 | 52 | ||
| 102 | - sockpp::udp6_socket udp6sock; | 53 | + osdev::components::socket-cpp::udp6_socket udp6sock; |
| 103 | if (!udp6sock) { | 54 | if (!udp6sock) { |
| 104 | cerr << "Error creating the UDP v6 socket: " << udp6sock.last_error_str() << endl; | 55 | cerr << "Error creating the UDP v6 socket: " << udp6sock.last_error_str() << endl; |
| 105 | return 1; | 56 | return 1; |
| 106 | } | 57 | } |
| 107 | 58 | ||
| 108 | - if (!udp6sock.bind(sockpp::inet6_address("localhost", port))) { | 59 | + if (!udp6sock.bind(osdev::components::socket-cpp::inet6_address("localhost", port))) { |
| 109 | cerr << "Error binding the UDP v6 socket: " << udp6sock.last_error_str() << endl; | 60 | cerr << "Error binding the UDP v6 socket: " << udp6sock.last_error_str() << endl; |
| 110 | return 1; | 61 | return 1; |
| 111 | } | 62 | } |
| 112 | 63 | ||
| 113 | // Spin up a thread to run the IPv4 socket. | 64 | // Spin up a thread to run the IPv4 socket. |
| 114 | - thread thr(run_echo<sockpp::udp_socket>, std::move(udpsock)); | 65 | + thread thr(run_echo<osdev::components::socket-cpp::udp_socket>, std::move(udpsock)); |
| 115 | thr.detach(); | 66 | thr.detach(); |
| 116 | 67 | ||
| 117 | // Run the IPv6 socket in this thread. (Call doesn't return) | 68 | // Run the IPv6 socket in this thread. (Call doesn't return) |
examples/unix/undgramecho.cpp
| 1 | -// udpecho.cpp | ||
| 2 | -// | ||
| 3 | -// Simple Unix-domain UDP echo client | ||
| 4 | -// | ||
| 5 | -// -------------------------------------------------------------------------- | ||
| 6 | -// This file is part of the "sockpp" C++ socket library. | ||
| 7 | -// | ||
| 8 | -// Copyright (c) 2019 Frank Pagliughi | ||
| 9 | -// All rights reserved. | ||
| 10 | -// | ||
| 11 | -// Redistribution and use in source and binary forms, with or without | ||
| 12 | -// modification, are permitted provided that the following conditions are | ||
| 13 | -// met: | ||
| 14 | -// | ||
| 15 | -// 1. Redistributions of source code must retain the above copyright notice, | ||
| 16 | -// this list of conditions and the following disclaimer. | ||
| 17 | -// | ||
| 18 | -// 2. Redistributions in binary form must reproduce the above copyright | ||
| 19 | -// notice, this list of conditions and the following disclaimer in the | ||
| 20 | -// documentation and/or other materials provided with the distribution. | ||
| 21 | -// | ||
| 22 | -// 3. Neither the name of the copyright holder nor the names of its | ||
| 23 | -// contributors may be used to endorse or promote products derived from this | ||
| 24 | -// software without specific prior written permission. | ||
| 25 | -// | ||
| 26 | -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
| 27 | -// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
| 28 | -// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 29 | -// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
| 30 | -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 31 | -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 32 | -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 33 | -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 34 | -// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 35 | -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 36 | -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 37 | -// -------------------------------------------------------------------------- | ||
| 38 | - | ||
| 39 | #include <iostream> | 1 | #include <iostream> |
| 40 | #include <string> | 2 | #include <string> |
| 41 | -#include "sockpp/unix_dgram_socket.h" | 3 | +#include "socket-cpp/unix_dgram_socket.h" |
| 42 | 4 | ||
| 43 | using namespace std; | 5 | using namespace std; |
| 44 | 6 | ||
| @@ -46,17 +8,17 @@ using namespace std; | @@ -46,17 +8,17 @@ using namespace std; | ||
| 46 | 8 | ||
| 47 | int main(int argc, char* argv[]) | 9 | int main(int argc, char* argv[]) |
| 48 | { | 10 | { |
| 49 | - sockpp::socket_initializer sockInit; | 11 | + osdev::components::socket-cpp::socket_initializer sockInit; |
| 50 | 12 | ||
| 51 | string cliAddr { "/tmp/undgramecho.sock" }, | 13 | string cliAddr { "/tmp/undgramecho.sock" }, |
| 52 | svrAddr { "/tmp/undgramechosvr.sock" }; | 14 | svrAddr { "/tmp/undgramechosvr.sock" }; |
| 53 | 15 | ||
| 54 | - sockpp::unix_dgram_socket sock; | 16 | + osdev::components::socket-cpp::unix_dgram_socket sock; |
| 55 | 17 | ||
| 56 | // A Unix-domain UDP client needs to bind to its own address | 18 | // A Unix-domain UDP client needs to bind to its own address |
| 57 | // before it can send or receive packets | 19 | // before it can send or receive packets |
| 58 | 20 | ||
| 59 | - if (!sock.bind(sockpp::unix_address(cliAddr))) { | 21 | + if (!sock.bind(osdev::components::socket-cpp::unix_address(cliAddr))) { |
| 60 | cerr << "Error connecting to client address at '" << cliAddr << "'" | 22 | cerr << "Error connecting to client address at '" << cliAddr << "'" |
| 61 | << "\n\t" << sock.last_error_str() << endl; | 23 | << "\n\t" << sock.last_error_str() << endl; |
| 62 | return 1; | 24 | return 1; |
| @@ -65,7 +27,7 @@ int main(int argc, char* argv[]) | @@ -65,7 +27,7 @@ int main(int argc, char* argv[]) | ||
| 65 | // "Connect" to the server address. This is a convenience to set the | 27 | // "Connect" to the server address. This is a convenience to set the |
| 66 | // default 'send_to' address, as there is no real connection. | 28 | // default 'send_to' address, as there is no real connection. |
| 67 | 29 | ||
| 68 | - if (!sock.connect(sockpp::unix_address(svrAddr))) { | 30 | + if (!sock.connect(osdev::components::socket-cpp::unix_address(svrAddr))) { |
| 69 | cerr << "Error connecting to server at '" << svrAddr << "'" | 31 | cerr << "Error connecting to server at '" << svrAddr << "'" |
| 70 | << "\n\t" << sock.last_error_str() << endl; | 32 | << "\n\t" << sock.last_error_str() << endl; |
| 71 | return 1; | 33 | return 1; |
examples/unix/undgramechosvr.cpp
| 1 | -// undgramechosvr.cpp | ||
| 2 | -// | ||
| 3 | -// A simple multi-threaded TCP/IP UDP echo server for sockpp library. | ||
| 4 | -// | ||
| 5 | -// This runs a UDP echo server for both IPv4 and IPv6, each in a separate | ||
| 6 | -// thread. They both use the same port number, either as provided by the user | ||
| 7 | -// on the command line, or defaulting to 12345. | ||
| 8 | -// | ||
| 9 | -// USAGE: | ||
| 10 | -// undgramechosvr [port] | ||
| 11 | -// | ||
| 12 | -// You can test with a netcat client, like: | ||
| 13 | -// $ nc -u localhost 12345 # IPv4 | ||
| 14 | -// $ nc -6u localhost 12345 # IPv6 | ||
| 15 | -// | ||
| 16 | -// -------------------------------------------------------------------------- | ||
| 17 | -// This file is part of the "sockpp" C++ socket library. | ||
| 18 | -// | ||
| 19 | -// Copyright (c) 2019 Frank Pagliughi | ||
| 20 | -// All rights reserved. | ||
| 21 | -// | ||
| 22 | -// Redistribution and use in source and binary forms, with or without | ||
| 23 | -// modification, are permitted provided that the following conditions are | ||
| 24 | -// met: | ||
| 25 | -// | ||
| 26 | -// 1. Redistributions of source code must retain the above copyright notice, | ||
| 27 | -// this list of conditions and the following disclaimer. | ||
| 28 | -// | ||
| 29 | -// 2. Redistributions in binary form must reproduce the above copyright | ||
| 30 | -// notice, this list of conditions and the following disclaimer in the | ||
| 31 | -// documentation and/or other materials provided with the distribution. | ||
| 32 | -// | ||
| 33 | -// 3. Neither the name of the copyright holder nor the names of its | ||
| 34 | -// contributors may be used to endorse or promote products derived from this | ||
| 35 | -// software without specific prior written permission. | ||
| 36 | -// | ||
| 37 | -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
| 38 | -// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
| 39 | -// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 40 | -// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
| 41 | -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 42 | -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 43 | -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 44 | -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 45 | -// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 46 | -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 47 | -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | -// -------------------------------------------------------------------------- | ||
| 49 | - | ||
| 50 | #include <iostream> | 1 | #include <iostream> |
| 51 | -#include "sockpp/unix_dgram_socket.h" | ||
| 52 | -#include "sockpp/version.h" | 2 | +#include "socket-cpp/unix_dgram_socket.h" |
| 3 | +#include "socket-cpp/version.h" | ||
| 53 | 4 | ||
| 54 | using namespace std; | 5 | using namespace std; |
| 55 | 6 | ||
| @@ -60,17 +11,17 @@ using namespace std; | @@ -60,17 +11,17 @@ using namespace std; | ||
| 60 | int main(int argc, char* argv[]) | 11 | int main(int argc, char* argv[]) |
| 61 | { | 12 | { |
| 62 | cout << "Sample Unix-domain datagram echo server for 'sockpp' " | 13 | cout << "Sample Unix-domain datagram echo server for 'sockpp' " |
| 63 | - << sockpp::SOCKPP_VERSION << '\n' << endl; | 14 | + << osdev::components::socket-cpp::SOCKPP_VERSION << '\n' << endl; |
| 64 | 15 | ||
| 65 | - sockpp::socket_initializer sockInit; | 16 | + osdev::components::socket-cpp::socket_initializer sockInit; |
| 66 | 17 | ||
| 67 | - sockpp::unix_dgram_socket sock; | 18 | + osdev::components::socket-cpp::unix_dgram_socket sock; |
| 68 | if (!sock) { | 19 | if (!sock) { |
| 69 | cerr << "Error creating the socket: " << sock.last_error_str() << endl; | 20 | cerr << "Error creating the socket: " << sock.last_error_str() << endl; |
| 70 | return 1; | 21 | return 1; |
| 71 | } | 22 | } |
| 72 | 23 | ||
| 73 | - if (!sock.bind(sockpp::unix_address("/tmp/undgramechosvr.sock"))) { | 24 | + if (!sock.bind(osdev::components::socket-cpp::unix_address("/tmp/undgramechosvr.sock"))) { |
| 74 | cerr << "Error binding the socket: " << sock.last_error_str() << endl; | 25 | cerr << "Error binding the socket: " << sock.last_error_str() << endl; |
| 75 | return 1; | 26 | return 1; |
| 76 | } | 27 | } |
| @@ -79,7 +30,7 @@ int main(int argc, char* argv[]) | @@ -79,7 +30,7 @@ int main(int argc, char* argv[]) | ||
| 79 | ssize_t n; | 30 | ssize_t n; |
| 80 | char buf[512]; | 31 | char buf[512]; |
| 81 | 32 | ||
| 82 | - sockpp::unix_address srcAddr; | 33 | + osdev::components::socket-cpp::unix_address srcAddr; |
| 83 | 34 | ||
| 84 | cout << "Awaiting packets on: '" << sock.address() << "'" << endl; | 35 | cout << "Awaiting packets on: '" << sock.address() << "'" << endl; |
| 85 | 36 |
examples/unix/unecho.cpp
| 1 | -// unecho.cpp | ||
| 2 | -// | ||
| 3 | -// Simple Unix-domain echo client | ||
| 4 | -// | ||
| 5 | -// -------------------------------------------------------------------------- | ||
| 6 | -// This file is part of the "sockpp" C++ socket library. | ||
| 7 | -// | ||
| 8 | -// Copyright (c) 2014-2017 Frank Pagliughi | ||
| 9 | -// All rights reserved. | ||
| 10 | -// | ||
| 11 | -// Redistribution and use in source and binary forms, with or without | ||
| 12 | -// modification, are permitted provided that the following conditions are | ||
| 13 | -// met: | ||
| 14 | -// | ||
| 15 | -// 1. Redistributions of source code must retain the above copyright notice, | ||
| 16 | -// this list of conditions and the following disclaimer. | ||
| 17 | -// | ||
| 18 | -// 2. Redistributions in binary form must reproduce the above copyright | ||
| 19 | -// notice, this list of conditions and the following disclaimer in the | ||
| 20 | -// documentation and/or other materials provided with the distribution. | ||
| 21 | -// | ||
| 22 | -// 3. Neither the name of the copyright holder nor the names of its | ||
| 23 | -// contributors may be used to endorse or promote products derived from this | ||
| 24 | -// software without specific prior written permission. | ||
| 25 | -// | ||
| 26 | -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
| 27 | -// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
| 28 | -// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 29 | -// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
| 30 | -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 31 | -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 32 | -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 33 | -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 34 | -// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 35 | -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 36 | -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 37 | -// -------------------------------------------------------------------------- | ||
| 38 | - | ||
| 39 | #include <iostream> | 1 | #include <iostream> |
| 40 | #include <string> | 2 | #include <string> |
| 41 | -#include "sockpp/unix_connector.h" | ||
| 42 | -#include "sockpp/version.h" | 3 | +#include "socket-cpp/unix_connector.h" |
| 4 | +#include "socket-cpp/version.h" | ||
| 43 | 5 | ||
| 44 | using namespace std; | 6 | using namespace std; |
| 45 | 7 | ||
| @@ -48,15 +10,15 @@ using namespace std; | @@ -48,15 +10,15 @@ using namespace std; | ||
| 48 | int main(int argc, char* argv[]) | 10 | int main(int argc, char* argv[]) |
| 49 | { | 11 | { |
| 50 | cout << "Sample Unix-domain echo client for 'sockpp' " | 12 | cout << "Sample Unix-domain echo client for 'sockpp' " |
| 51 | - << sockpp::SOCKPP_VERSION << '\n' << endl; | 13 | + << osdev::components::socket-cpp::SOCKPP_VERSION << '\n' << endl; |
| 52 | 14 | ||
| 53 | string path = (argc > 1) ? argv[1] : "/tmp/unechosvr.sock"; | 15 | string path = (argc > 1) ? argv[1] : "/tmp/unechosvr.sock"; |
| 54 | 16 | ||
| 55 | - sockpp::socket_initializer sockInit; | 17 | + osdev::components::socket-cpp::socket_initializer sockInit; |
| 56 | 18 | ||
| 57 | - sockpp::unix_connector conn; | 19 | + osdev::components::socket-cpp::unix_connector conn; |
| 58 | 20 | ||
| 59 | - bool ok = conn.connect(sockpp::unix_address(path)); | 21 | + bool ok = conn.connect(osdev::components::socket-cpp::unix_address(path)); |
| 60 | if (!ok) { | 22 | if (!ok) { |
| 61 | cerr << "Error connecting to UNIX socket at " << path | 23 | cerr << "Error connecting to UNIX socket at " << path |
| 62 | << "\n\t" << conn.last_error_str() << endl; | 24 | << "\n\t" << conn.last_error_str() << endl; |
examples/unix/unechosvr.cpp
| 1 | -// unechosvr.cpp | ||
| 2 | -// | ||
| 3 | -// A multi-threaded UNIX-domain echo server for sockpp library. | ||
| 4 | -// This is a simple thread-per-connection UNIX server. | ||
| 5 | -// | ||
| 6 | -// USAGE: | ||
| 7 | -// unechosvr [path] | ||
| 8 | -// | ||
| 9 | -// -------------------------------------------------------------------------- | ||
| 10 | -// This file is part of the "sockpp" C++ socket library. | ||
| 11 | -// | ||
| 12 | -// Copyright (c) 2014-2017 Frank Pagliughi | ||
| 13 | -// All rights reserved. | ||
| 14 | -// | ||
| 15 | -// Redistribution and use in source and binary forms, with or without | ||
| 16 | -// modification, are permitted provided that the following conditions are | ||
| 17 | -// met: | ||
| 18 | -// | ||
| 19 | -// 1. Redistributions of source code must retain the above copyright notice, | ||
| 20 | -// this list of conditions and the following disclaimer. | ||
| 21 | -// | ||
| 22 | -// 2. Redistributions in binary form must reproduce the above copyright | ||
| 23 | -// notice, this list of conditions and the following disclaimer in the | ||
| 24 | -// documentation and/or other materials provided with the distribution. | ||
| 25 | -// | ||
| 26 | -// 3. Neither the name of the copyright holder nor the names of its | ||
| 27 | -// contributors may be used to endorse or promote products derived from this | ||
| 28 | -// software without specific prior written permission. | ||
| 29 | -// | ||
| 30 | -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
| 31 | -// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
| 32 | -// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 33 | -// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
| 34 | -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 35 | -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 36 | -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 37 | -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 38 | -// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 39 | -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 40 | -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 41 | -// -------------------------------------------------------------------------- | ||
| 42 | - | ||
| 43 | #include <iostream> | 1 | #include <iostream> |
| 44 | #include <thread> | 2 | #include <thread> |
| 45 | -#include "sockpp/unix_acceptor.h" | ||
| 46 | -#include "sockpp/version.h" | 3 | +#include "socket-cpp/unix_acceptor.h" |
| 4 | +#include "socket-cpp/version.h" | ||
| 47 | 5 | ||
| 48 | using namespace std; | 6 | using namespace std; |
| 49 | 7 | ||
| @@ -52,7 +10,7 @@ using namespace std; | @@ -52,7 +10,7 @@ using namespace std; | ||
| 52 | // Ownership of the socket object is transferred to the thread, so when this | 10 | // Ownership of the socket object is transferred to the thread, so when this |
| 53 | // function exits, the socket is automatically closed. | 11 | // function exits, the socket is automatically closed. |
| 54 | 12 | ||
| 55 | -void run_echo(sockpp::unix_socket sock) | 13 | +void run_echo(osdev::components::socket-cpp::unix_socket sock) |
| 56 | { | 14 | { |
| 57 | int n; | 15 | int n; |
| 58 | char buf[512]; | 16 | char buf[512]; |
| @@ -71,7 +29,7 @@ void run_echo(sockpp::unix_socket sock) | @@ -71,7 +29,7 @@ void run_echo(sockpp::unix_socket sock) | ||
| 71 | int main(int argc, char* argv[]) | 29 | int main(int argc, char* argv[]) |
| 72 | { | 30 | { |
| 73 | cout << "Sample Unix-domain echo server for 'sockpp' " | 31 | cout << "Sample Unix-domain echo server for 'sockpp' " |
| 74 | - << sockpp::SOCKPP_VERSION << '\n' << endl; | 32 | + << osdev::components::socket-cpp::SOCKPP_VERSION << '\n' << endl; |
| 75 | 33 | ||
| 76 | string path = "/tmp/unechosvr.sock"; | 34 | string path = "/tmp/unechosvr.sock"; |
| 77 | 35 | ||
| @@ -79,10 +37,10 @@ int main(int argc, char* argv[]) | @@ -79,10 +37,10 @@ int main(int argc, char* argv[]) | ||
| 79 | path = argv[1]; | 37 | path = argv[1]; |
| 80 | } | 38 | } |
| 81 | 39 | ||
| 82 | - sockpp::socket_initializer sockInit; | ||
| 83 | - sockpp::unix_acceptor acc; | 40 | + osdev::components::socket-cpp::socket_initializer sockInit; |
| 41 | + osdev::components::socket-cpp::unix_acceptor acc; | ||
| 84 | 42 | ||
| 85 | - bool ok = acc.open(sockpp::unix_address(path)); | 43 | + bool ok = acc.open(osdev::components::socket-cpp::unix_address(path)); |
| 86 | 44 | ||
| 87 | if (!ok) { | 45 | if (!ok) { |
| 88 | cerr << "Error creating the acceptor: " << acc.last_error_str() << endl; | 46 | cerr << "Error creating the acceptor: " << acc.last_error_str() << endl; |
examples/unix/unechotest.cpp
| 1 | -// unechotest.cpp | ||
| 2 | -// | ||
| 3 | -// Unix-domain echo timing test client | ||
| 4 | -// | ||
| 5 | -// -------------------------------------------------------------------------- | ||
| 6 | -// This file is part of the "sockpp" C++ socket library. | ||
| 7 | -// | ||
| 8 | -// Copyright (c) 2020 Frank Pagliughi | ||
| 9 | -// All rights reserved. | ||
| 10 | -// | ||
| 11 | -// Redistribution and use in source and binary forms, with or without | ||
| 12 | -// modification, are permitted provided that the following conditions are | ||
| 13 | -// met: | ||
| 14 | -// | ||
| 15 | -// 1. Redistributions of source code must retain the above copyright notice, | ||
| 16 | -// this list of conditions and the following disclaimer. | ||
| 17 | -// | ||
| 18 | -// 2. Redistributions in binary form must reproduce the above copyright | ||
| 19 | -// notice, this list of conditions and the following disclaimer in the | ||
| 20 | -// documentation and/or other materials provided with the distribution. | ||
| 21 | -// | ||
| 22 | -// 3. Neither the name of the copyright holder nor the names of its | ||
| 23 | -// contributors may be used to endorse or promote products derived from this | ||
| 24 | -// software without specific prior written permission. | ||
| 25 | -// | ||
| 26 | -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
| 27 | -// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
| 28 | -// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 29 | -// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
| 30 | -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 31 | -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 32 | -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 33 | -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 34 | -// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 35 | -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 36 | -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 37 | -// -------------------------------------------------------------------------- | ||
| 38 | - | ||
| 39 | #include <iostream> | 1 | #include <iostream> |
| 40 | #include <string> | 2 | #include <string> |
| 41 | #include <chrono> | 3 | #include <chrono> |
| 42 | #include <random> | 4 | #include <random> |
| 43 | -#include "sockpp/unix_connector.h" | ||
| 44 | -#include "sockpp/version.h" | 5 | +#include "socket-cpp/unix_connector.h" |
| 6 | +#include "socket-cpp/version.h" | ||
| 45 | 7 | ||
| 46 | using namespace std; | 8 | using namespace std; |
| 47 | using namespace std::chrono; | 9 | using namespace std::chrono; |
| @@ -56,18 +18,18 @@ using fpsec = std::chrono::duration<double, std::chrono::seconds::period>; | @@ -56,18 +18,18 @@ using fpsec = std::chrono::duration<double, std::chrono::seconds::period>; | ||
| 56 | int main(int argc, char* argv[]) | 18 | int main(int argc, char* argv[]) |
| 57 | { | 19 | { |
| 58 | cout << "Unix-domain echo timing test client for 'sockpp' " | 20 | cout << "Unix-domain echo timing test client for 'sockpp' " |
| 59 | - << sockpp::SOCKPP_VERSION << '\n' << endl; | 21 | + << osdev::components::socket-cpp::SOCKPP_VERSION << '\n' << endl; |
| 60 | 22 | ||
| 61 | string path = (argc > 1) ? argv[1] : "/tmp/unechosvr.sock"; | 23 | string path = (argc > 1) ? argv[1] : "/tmp/unechosvr.sock"; |
| 62 | size_t n = (argc > 2) ? size_t(atoll(argv[2])) : DFLT_N; | 24 | size_t n = (argc > 2) ? size_t(atoll(argv[2])) : DFLT_N; |
| 63 | size_t sz = (argc > 3) ? size_t(atoll(argv[3])) : DFLT_SZ; | 25 | size_t sz = (argc > 3) ? size_t(atoll(argv[3])) : DFLT_SZ; |
| 64 | 26 | ||
| 65 | - sockpp::socket_initializer sockInit; | 27 | + osdev::components::socket-cpp::socket_initializer sockInit; |
| 66 | 28 | ||
| 67 | auto t_start = high_resolution_clock::now(); | 29 | auto t_start = high_resolution_clock::now(); |
| 68 | - sockpp::unix_connector conn; | 30 | + osdev::components::socket-cpp::unix_connector conn; |
| 69 | 31 | ||
| 70 | - bool ok = conn.connect(sockpp::unix_address(path)); | 32 | + bool ok = conn.connect(osdev::components::socket-cpp::unix_address(path)); |
| 71 | if (!ok) { | 33 | if (!ok) { |
| 72 | cerr << "Error connecting to UNIX socket at " << path | 34 | cerr << "Error connecting to UNIX socket at " << path |
| 73 | << "\n\t" << conn.last_error_str() << endl; | 35 | << "\n\t" << conn.last_error_str() << endl; |
include/socket-cpp/tcp_acceptor.h
| 1 | +#pragma once | ||
| 1 | 2 | ||
| 2 | -#ifndef __sockpp_tcp_acceptor_h | ||
| 3 | -#define __sockpp_tcp_acceptor_h | 3 | +#include "socket-cpp/acceptor.h" |
| 4 | +#include "socket-cpp/tcp_socket.h" | ||
| 4 | 5 | ||
| 5 | -#include "sockpp/acceptor.h" | ||
| 6 | -#include "sockpp/tcp_socket.h" | ||
| 7 | - | ||
| 8 | -namespace sockpp { | ||
| 9 | - | ||
| 10 | -///////////////////////////////////////////////////////////////////////////// | 6 | +namespace osdev { |
| 7 | +namespace components { | ||
| 8 | +namespace socket-cpp { | ||
| 11 | 9 | ||
| 12 | /// Class for creating a TCP server. | 10 | /// Class for creating a TCP server. |
| 13 | /// Objects of this class bind and listen on TCP ports for incoming | 11 | /// Objects of this class bind and listen on TCP ports for incoming |
| @@ -18,9 +16,7 @@ namespace sockpp { | @@ -18,9 +16,7 @@ namespace sockpp { | ||
| 18 | 16 | ||
| 19 | using tcp_acceptor = acceptor_tmpl<tcp_socket>; | 17 | using tcp_acceptor = acceptor_tmpl<tcp_socket>; |
| 20 | 18 | ||
| 21 | -///////////////////////////////////////////////////////////////////////////// | ||
| 22 | -// end namespace sockpp | ||
| 23 | -}; | ||
| 24 | - | ||
| 25 | -#endif // __sockpp_tcp_acceptor_h | 19 | +} // End namespace socket-cpp |
| 20 | +} // End namespace components | ||
| 21 | +} // End namespace osdev | ||
| 26 | 22 |
include/socket-cpp/tcp_connector.h
| 1 | +#pragma once | ||
| 1 | 2 | ||
| 2 | - | ||
| 3 | -#ifndef __sockpp_tcp_connector_h | ||
| 4 | -#define __sockpp_tcp_connector_h | ||
| 5 | - | ||
| 6 | -#include "sockpp/connector.h" | ||
| 7 | -#include "sockpp/tcp_socket.h" | ||
| 8 | - | ||
| 9 | -namespace sockpp { | ||
| 10 | - | ||
| 11 | -///////////////////////////////////////////////////////////////////////////// | 3 | +#include "socket-cpp/connector.h" |
| 4 | +#include "socket-cpp/tcp_socket.h" | ||
| 12 | 5 | ||
| 13 | /** IPv4 active, connector (client) socket. */ | 6 | /** IPv4 active, connector (client) socket. */ |
| 14 | using tcp_connector = connector_tmpl<tcp_socket>; | 7 | using tcp_connector = connector_tmpl<tcp_socket>; |
| 15 | 8 | ||
| 16 | -///////////////////////////////////////////////////////////////////////////// | ||
| 17 | -// end namespace sockpp | ||
| 18 | -}; | 9 | +} // End namespace socket-cpp |
| 10 | +} // End namespace components | ||
| 11 | +} // End namespace osdev | ||
| 19 | 12 | ||
| 20 | -#endif // __sockpp_tcp_connector_h |
include/socket-cpp/tcp_socket.h
| 1 | +#pragma once | ||
| 1 | 2 | ||
| 2 | -#ifndef __sockpp_tcp_socket_h | ||
| 3 | -#define __sockpp_tcp_socket_h | 3 | +#include "socket-cpp/stream_socket.h" |
| 4 | +#include "socket-cpp/inet_address.h" | ||
| 4 | 5 | ||
| 5 | -#include "sockpp/stream_socket.h" | ||
| 6 | -#include "sockpp/inet_address.h" | ||
| 7 | - | ||
| 8 | -namespace sockpp { | ||
| 9 | - | ||
| 10 | -///////////////////////////////////////////////////////////////////////////// | 6 | +namespace osdev { |
| 7 | +namespace components { | ||
| 8 | +namespace socket-cpp { | ||
| 11 | 9 | ||
| 12 | /** IPv4 streaming TCP socket */ | 10 | /** IPv4 streaming TCP socket */ |
| 13 | using tcp_socket = stream_socket_tmpl<inet_address>; | 11 | using tcp_socket = stream_socket_tmpl<inet_address>; |
| 14 | 12 | ||
| 15 | -///////////////////////////////////////////////////////////////////////////// | ||
| 16 | -// end namespace sockpp | ||
| 17 | -} | ||
| 18 | - | ||
| 19 | -#endif // __sockpp_tcp_socket_h | 13 | +} // End namespace socket-cpp |
| 14 | +} // End namespace components | ||
| 15 | +} // End namespace osdev | ||
| 20 | 16 |
include/socket-cpp/udp6_socket.h
| 1 | -/** | ||
| 2 | - * @file udp6_socket.h | ||
| 3 | - * | ||
| 4 | - * Class (typedef) for UDP v6 socket. | ||
| 5 | - * | ||
| 6 | - * @author Frank Pagliughi | ||
| 7 | - * @author SoRo Systems, Inc. | ||
| 8 | - * @author www.sorosys.com | ||
| 9 | - * | ||
| 10 | - * @date August 2019 | ||
| 11 | - */ | 1 | +#pragma once |
| 12 | 2 | ||
| 13 | -// -------------------------------------------------------------------------- | ||
| 14 | -// This file is part of the "sockpp" C++ socket library. | ||
| 15 | -// | ||
| 16 | -// Copyright (c) 2019 Frank Pagliughi | ||
| 17 | -// All rights reserved. | ||
| 18 | -// | ||
| 19 | -// Redistribution and use in source and binary forms, with or without | ||
| 20 | -// modification, are permitted provided that the following conditions are | ||
| 21 | -// met: | ||
| 22 | -// | ||
| 23 | -// 1. Redistributions of source code must retain the above copyright notice, | ||
| 24 | -// this list of conditions and the following disclaimer. | ||
| 25 | -// | ||
| 26 | -// 2. Redistributions in binary form must reproduce the above copyright | ||
| 27 | -// notice, this list of conditions and the following disclaimer in the | ||
| 28 | -// documentation and/or other materials provided with the distribution. | ||
| 29 | -// | ||
| 30 | -// 3. Neither the name of the copyright holder nor the names of its | ||
| 31 | -// contributors may be used to endorse or promote products derived from this | ||
| 32 | -// software without specific prior written permission. | ||
| 33 | -// | ||
| 34 | -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
| 35 | -// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
| 36 | -// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 37 | -// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
| 38 | -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 39 | -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 40 | -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 41 | -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 42 | -// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 43 | -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 44 | -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 45 | -// -------------------------------------------------------------------------- | 3 | +#include "socket-cpp/datagram_socket.h" |
| 4 | +#include "socket-cpp/inet6_address.h" | ||
| 46 | 5 | ||
| 47 | -#ifndef __sockpp_udp6_socket_h | ||
| 48 | -#define __sockpp_udp6_socket_h | ||
| 49 | - | ||
| 50 | -#include "sockpp/datagram_socket.h" | ||
| 51 | -#include "sockpp/inet6_address.h" | ||
| 52 | - | ||
| 53 | -namespace sockpp { | ||
| 54 | - | ||
| 55 | -///////////////////////////////////////////////////////////////////////////// | 6 | +namespace osdev { |
| 7 | +namespace components { | ||
| 8 | +namespace socket-cpp { | ||
| 56 | 9 | ||
| 57 | /** UDP datagram socket type for IPv6 */ | 10 | /** UDP datagram socket type for IPv6 */ |
| 58 | using udp6_socket = datagram_socket_tmpl<inet6_address>; | 11 | using udp6_socket = datagram_socket_tmpl<inet6_address>; |
| 59 | 12 | ||
| 60 | -///////////////////////////////////////////////////////////////////////////// | ||
| 61 | -// end namespace sockpp | ||
| 62 | -} | ||
| 63 | - | ||
| 64 | -#endif // __sockpp_udp6_socket_h | 13 | +} // End namespace socket-cpp |
| 14 | +} // End namespace components | ||
| 15 | +} // End namespace osdev | ||
| 65 | 16 |
include/socket-cpp/udp_socket.h
| 1 | +#pragma once | ||
| 1 | 2 | ||
| 3 | +#include "socket-cpp/datagram_socket.h" | ||
| 4 | +#include "socket-cpp/inet_address.h" | ||
| 2 | 5 | ||
| 3 | -#include "sockpp/datagram_socket.h" | ||
| 4 | -#include "sockpp/inet_address.h" | ||
| 5 | - | ||
| 6 | -namespace sockpp { | ||
| 7 | - | ||
| 8 | -///////////////////////////////////////////////////////////////////////////// | 6 | +namespace osdev { |
| 7 | +namespace components { | ||
| 8 | +namespace socket-cpp { | ||
| 9 | 9 | ||
| 10 | /** UDP datagram socket type for IPv4 */ | 10 | /** UDP datagram socket type for IPv4 */ |
| 11 | using udp_socket = datagram_socket_tmpl<inet_address>; | 11 | using udp_socket = datagram_socket_tmpl<inet_address>; |
| 12 | 12 | ||
| 13 | -///////////////////////////////////////////////////////////////////////////// | ||
| 14 | -// end namespace sockpp | ||
| 15 | -} | ||
| 16 | - | ||
| 17 | -#endif // __sockpp_udp_socket_h | 13 | +} // End namespace socket-cpp |
| 14 | +} // End namespace components | ||
| 15 | +} // End namespace osdev | ||
| 18 | 16 |
include/socket-cpp/unix_acceptor.h
| 1 | +#pragma once | ||
| 1 | 2 | ||
| 2 | -#include "sockpp/acceptor.h" | ||
| 3 | -#include "sockpp/unix_stream_socket.h" | 3 | +#include "socket-cpp/acceptor.h" |
| 4 | +#include "socket-cpp/unix_stream_socket.h" | ||
| 4 | 5 | ||
| 5 | -namespace sockpp { | ||
| 6 | - | ||
| 7 | -///////////////////////////////////////////////////////////////////////////// | 6 | +namespace osdev { |
| 7 | +namespace components { | ||
| 8 | +namespace socket-cpp { | ||
| 8 | 9 | ||
| 9 | /// Class for creating a Unix-domain server. | 10 | /// Class for creating a Unix-domain server. |
| 10 | /// Objects of this class bind and listen on Unix-domain ports for | 11 | /// Objects of this class bind and listen on Unix-domain ports for |
| @@ -61,9 +62,7 @@ public: | @@ -61,9 +62,7 @@ public: | ||
| 61 | unix_socket accept() { return unix_socket(base::accept()); } | 62 | unix_socket accept() { return unix_socket(base::accept()); } |
| 62 | }; | 63 | }; |
| 63 | 64 | ||
| 64 | -///////////////////////////////////////////////////////////////////////////// | ||
| 65 | -// end namespace sockpp | ||
| 66 | -}; | ||
| 67 | - | ||
| 68 | -#endif // __sockpp_unix_acceptor_h | 65 | +} // End namespace socket-cpp |
| 66 | +} // End namespace components | ||
| 67 | +} // End namespace osdev | ||
| 69 | 68 |
include/socket-cpp/unix_address.h
| 1 | -/** | ||
| 2 | - * @file unix_address.h | ||
| 3 | - * | ||
| 4 | - * Class for a UNIX-domain socket address. | ||
| 5 | - * | ||
| 6 | - * @author Frank Pagliughi | ||
| 7 | - * @author SoRo Systems, Inc. | ||
| 8 | - * @author www.sorosys.com | ||
| 9 | - * | ||
| 10 | - * @date February 2014 | ||
| 11 | - */ | ||
| 12 | - | ||
| 13 | -// -------------------------------------------------------------------------- | ||
| 14 | -// This file is part of the "sockpp" C++ socket library. | ||
| 15 | -// | ||
| 16 | -// Copyright (c) 2014-2017 Frank Pagliughi | ||
| 17 | -// All rights reserved. | ||
| 18 | -// | ||
| 19 | -// Redistribution and use in source and binary forms, with or without | ||
| 20 | -// modification, are permitted provided that the following conditions are | ||
| 21 | -// met: | ||
| 22 | -// | ||
| 23 | -// 1. Redistributions of source code must retain the above copyright notice, | ||
| 24 | -// this list of conditions and the following disclaimer. | ||
| 25 | -// | ||
| 26 | -// 2. Redistributions in binary form must reproduce the above copyright | ||
| 27 | -// notice, this list of conditions and the following disclaimer in the | ||
| 28 | -// documentation and/or other materials provided with the distribution. | ||
| 29 | -// | ||
| 30 | -// 3. Neither the name of the copyright holder nor the names of its | ||
| 31 | -// contributors may be used to endorse or promote products derived from this | ||
| 32 | -// software without specific prior written permission. | ||
| 33 | -// | ||
| 34 | -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
| 35 | -// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
| 36 | -// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 37 | -// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
| 38 | -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 39 | -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 40 | -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 41 | -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 42 | -// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 43 | -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 44 | -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 45 | -// -------------------------------------------------------------------------- | ||
| 46 | - | ||
| 47 | -#ifndef __sockpp_unix_addr_h | ||
| 48 | -#define __sockpp_unix_addr_h | 1 | +#pragma once |
| 49 | 2 | ||
| 50 | -#include "sockpp/platform.h" | ||
| 51 | -#include "sockpp/sock_address.h" | 3 | +#include "socket-cpp/platform.h" |
| 4 | +#include "socket-cpp/sock_address.h" | ||
| 52 | #include <iostream> | 5 | #include <iostream> |
| 53 | #include <string> | 6 | #include <string> |
| 54 | #include <cstring> | 7 | #include <cstring> |
| 55 | #include <sys/un.h> | 8 | #include <sys/un.h> |
| 56 | 9 | ||
| 57 | -namespace sockpp { | ||
| 58 | - | ||
| 59 | -///////////////////////////////////////////////////////////////////////////// | 10 | +namespace osdev { |
| 11 | +namespace components { | ||
| 12 | +namespace socket-cpp { | ||
| 60 | 13 | ||
| 61 | /** | 14 | /** |
| 62 | * Class that represents a UNIX domain address. | 15 | * Class that represents a UNIX domain address. |
| @@ -184,9 +137,7 @@ public: | @@ -184,9 +137,7 @@ public: | ||
| 184 | */ | 137 | */ |
| 185 | std::ostream& operator<<(std::ostream& os, const unix_address& addr); | 138 | std::ostream& operator<<(std::ostream& os, const unix_address& addr); |
| 186 | 139 | ||
| 187 | -///////////////////////////////////////////////////////////////////////////// | ||
| 188 | -// end namespace sockpp | ||
| 189 | -} | ||
| 190 | - | ||
| 191 | -#endif // __sockpp_unix_addr_h | 140 | +} // End namespace socket-cpp |
| 141 | +} // End namespace components | ||
| 142 | +} // End namespace osdev | ||
| 192 | 143 |
include/socket-cpp/unix_connector.h
| 1 | +#pragma once | ||
| 1 | 2 | ||
| 2 | -#include "sockpp/connector.h" | ||
| 3 | -#include "sockpp/unix_stream_socket.h" | 3 | +#include "socket-cpp/connector.h" |
| 4 | +#include "socket-cpp/unix_stream_socket.h" | ||
| 4 | 5 | ||
| 5 | -namespace sockpp { | ||
| 6 | - | ||
| 7 | -///////////////////////////////////////////////////////////////////////////// | 6 | +namespace osdev { |
| 7 | +namespace components { | ||
| 8 | +namespace socket-cpp { | ||
| 8 | 9 | ||
| 9 | /** Unix-domain active connector socket. */ | 10 | /** Unix-domain active connector socket. */ |
| 10 | using unix_connector = connector_tmpl<unix_socket, unix_address>; | 11 | using unix_connector = connector_tmpl<unix_socket, unix_address>; |
| 11 | 12 | ||
| 12 | -///////////////////////////////////////////////////////////////////////////// | ||
| 13 | -// end namespace sockpp | ||
| 14 | -}; | ||
| 15 | - | ||
| 16 | -#endif // __sockpp_unix_connector_h | 13 | +} // End namespace socket-cpp |
| 14 | +} // End namespace components | ||
| 15 | +} // End namespace osdev | ||
| 17 | 16 |
include/socket-cpp/unix_dgram_socket.h
| 1 | +#pragma once | ||
| 1 | 2 | ||
| 3 | +#include "socket-cpp/datagram_socket.h" | ||
| 4 | +#include "socket-cpp/unix_address.h" | ||
| 2 | 5 | ||
| 3 | -#include "sockpp/datagram_socket.h" | ||
| 4 | -#include "sockpp/unix_address.h" | ||
| 5 | - | ||
| 6 | -namespace sockpp { | ||
| 7 | - | ||
| 8 | -///////////////////////////////////////////////////////////////////////////// | 6 | +namespace osdev { |
| 7 | +namespace components { | ||
| 8 | +namespace socket-cpp { | ||
| 9 | 9 | ||
| 10 | /** Unix-domain datagram socket */ | 10 | /** Unix-domain datagram socket */ |
| 11 | using unix_datagram_socket = datagram_socket_tmpl<unix_address>; | 11 | using unix_datagram_socket = datagram_socket_tmpl<unix_address>; |
| @@ -13,9 +13,7 @@ using unix_datagram_socket = datagram_socket_tmpl<unix_address>; | @@ -13,9 +13,7 @@ using unix_datagram_socket = datagram_socket_tmpl<unix_address>; | ||
| 13 | /** Unix-domain datagram socket (same as `unix_datagram_socket`) */ | 13 | /** Unix-domain datagram socket (same as `unix_datagram_socket`) */ |
| 14 | using unix_dgram_socket = unix_datagram_socket; | 14 | using unix_dgram_socket = unix_datagram_socket; |
| 15 | 15 | ||
| 16 | -///////////////////////////////////////////////////////////////////////////// | ||
| 17 | -// end namespace sockpp | ||
| 18 | -} | ||
| 19 | - | ||
| 20 | -#endif // __sockpp_unix_dgram_socket_h | 16 | +} // End namespace socket-cpp |
| 17 | +} // End namespace components | ||
| 18 | +} // End namespace osdev | ||
| 21 | 19 |
include/socket-cpp/unix_stream_socket.h
| 1 | +$pragma once | ||
| 1 | 2 | ||
| 3 | +#include "socket-cpp/stream_socket.h" | ||
| 4 | +#include "socket-cpp/unix_address.h" | ||
| 2 | 5 | ||
| 3 | -#include "sockpp/stream_socket.h" | ||
| 4 | -#include "sockpp/unix_address.h" | ||
| 5 | - | ||
| 6 | -namespace sockpp { | ||
| 7 | - | ||
| 8 | -///////////////////////////////////////////////////////////////////////////// | 6 | +namespace osdev { |
| 7 | +namespace components { | ||
| 8 | +namespace socket-cpp { | ||
| 9 | 9 | ||
| 10 | /** Streaming Unix-domain socket */ | 10 | /** Streaming Unix-domain socket */ |
| 11 | using unix_stream_socket = stream_socket_tmpl<unix_address>; | 11 | using unix_stream_socket = stream_socket_tmpl<unix_address>; |
| @@ -13,9 +13,7 @@ using unix_stream_socket = stream_socket_tmpl<unix_address>; | @@ -13,9 +13,7 @@ using unix_stream_socket = stream_socket_tmpl<unix_address>; | ||
| 13 | /** Streaming Unix-domain socket (same as a `unix_stream_socket` */ | 13 | /** Streaming Unix-domain socket (same as a `unix_stream_socket` */ |
| 14 | using unix_socket = unix_stream_socket; | 14 | using unix_socket = unix_stream_socket; |
| 15 | 15 | ||
| 16 | -///////////////////////////////////////////////////////////////////////////// | ||
| 17 | -// end namespace sockpp | ||
| 18 | -} | ||
| 19 | - | ||
| 20 | -#endif // __sockpp_unix_stream_socket_h | 16 | +} // End namespace socket-cpp |
| 17 | +} // End namespace components | ||
| 18 | +} // End namespace osdev | ||
| 21 | 19 |