14 #include <ecl/config/ecl.hpp> 16 #include "../../include/ecl/io/poll.hpp" 17 #include "../../include/ecl/io/socketpair.hpp" 26 #define DATA1 "In Xanadu, did Kublai Khan . . ." 27 #define DATA2 "A stately pleasure dome decree . . ." 41 return WSAGetLastError();
59 int main(
int argc,
char **argv) {
63 std::cout << error.
what() << std::endl;
71 std::cout << error.
what() << std::endl;
72 std::cout <<
"SocketPair Error: " <<
socket_error() << std::endl;
77 pfd[0].events = POLLIN;
80 pfd[1].events = POLLIN;
83 int poll_timeout = 500;
85 unsigned int count = 0;
86 while ( count < 10 ) {
89 }
else if ( result > 0 ) {
90 char receiving_buffer[256];
92 for (
unsigned int i = 0; i < 2; ++i ) {
93 if ( pfd[i].revents == POLLIN ) {
95 while ( ( n = ::recv(
socket_pair[i], reinterpret_cast<char*>(receiving_buffer), 256, 0) ) > 0 ) {
97 while( (n = read(
socket_pair[i], receiving_buffer, 256)) > 0) {
99 std::cout << receiving_buffer << std::endl;
106 std::cerr <<
"Failed to write to the socket." << std::endl;
114 std::cerr <<
"Failed to write to the socket." << std::endl;
129 std::cerr <<
"Failed to write to the socket." << std::endl;
ecl::socket_descriptor socket_pair[2]
int main(int argc, char **argv)
ecl_io_PUBLIC SocketError socketpair(socket_descriptor socket_fd_pair[2], const bool non_blocking=false)
Creates a socket pair internal to the current process.
virtual ErrorFlag flag() const
int socket_descriptor
Cross-platform typedef for a socket file descriptor.
ecl_io_PUBLIC SocketError init_sockets()
Initialise the socket subsystem.
struct pollfd socket_pollfd
ecl_io_PUBLIC int poll_sockets(socket_pollfd *fds, nfds_t nfds, int timeout)
ecl_io_PUBLIC SocketError close_socket(const socket_descriptor &sock)
Close a socket.
Extends the generic error handler with socket specific error strings.
virtual const char * what() const