Sponge
CS144's user-space TCP library
socket_example_3.cc
Go to the documentation of this file.
1 // create a pair of stream sockets
3 SystemCall("socketpair", ::socketpair(AF_UNIX, SOCK_STREAM, 0, fds.data()));
5 
6 pipe1.write("hi there");
7 auto recvd = pipe2.read();
8 
9 pipe2.write("hi yourself");
10 auto recvd2 = pipe1.read();
11 
12 if (recvd != "hi there" || recvd2 != "hi yourself") {
13  throw std::runtime_error("wrong data received");
14 }
A reference-counted handle to a file descriptor.
size_t write(const char *str, const bool write_all=true)
Write a string, possibly blocking until all is written.
std::string read(const size_t limit=std::numeric_limits< size_t >::max())
Read up to limit bytes.
A wrapper around Unix-domain stream sockets.
Definition: socket.hh:113
LocalStreamSocket pipe2
std::array< int, 2 > fds
auto recvd2
LocalStreamSocket pipe1
SystemCall("socketpair", ::socketpair(AF_UNIX, SOCK_STREAM, 0, fds.data()))
auto recvd