33 using namespace basis;
41 #define LOG(to_print) EMERGENCY_LOG(program_wide_logger().get(), astring(to_print))
81 outcome ret = spocket::NO_CONNECTION;
84 if (ret == spocket::OKAY)
break;
85 if (ret != spocket::NO_CONNECTION)
break;
86 time_control::sleep_ms(100);
88 return ret == spocket::OKAY;
94 _root_server =
new spocket(*_where);
97 LOG(
"already have a socket for accept!");
100 outcome ret = spocket::NO_CONNECTION;
102 ret = _root_server->
accept(_socket,
false);
103 if (ret == spocket::OKAY)
break;
104 if (ret != spocket::NO_CONNECTION)
break;
105 if (!wait)
return true;
106 time_control::sleep_ms(100);
109 return ret == spocket::OKAY;
120 #ifdef DEBUG_SPOCKET_TESTER
121 LOG(
"into do a send");
125 worked = _socket->
send(buffer, size, len_sent);
126 if (worked == spocket::NONE_READY) {
130 }
else if (worked == spocket::PARTIAL) {
140 #ifdef DEBUG_SPOCKET_TESTER
141 LOG(
"got out of loop");
147 if ( (worked != spocket::OKAY) && (worked != spocket::PARTIAL) ) {
148 LOG(
astring(
"No data went out on the socket: ")
149 + spocket::outcome_name(worked));
152 if (len_sent != size) {
153 LOG(
a_sprintf(
"partial send on socket, %d bytes instead of %d, recurse.",
155 return do_a_send(buffer + len_sent, size - len_sent, stats);
168 #ifdef DEBUG_SPOCKET_TESTER
169 LOG(
"into do a rcv");
174 while ( (full_length < size_expected) && (
time_stamp() < when_to_leave) ) {
178 if (ret != spocket::OKAY) {
179 if (ret == spocket::NONE_READY) {
180 if (len != 0)
LOG(
a_sprintf(
"supposedly nothing was received (%d bytes)", len));
186 if (ret == spocket::OKAY)
189 int receive_duration = int(
time_stamp().value()
190 - start_of_receive.
value());
193 #ifdef DEBUG_SPOCKET_TESTER
198 LOG(
"Our socket has been disconnected.");
200 }
else if (len < 0) {
202 LOG(
astring(
"The receive failed with an error ")
203 + critical_events::system_error_text(errno));
210 if (full_length != size_expected)
211 LOG(
a_sprintf(
"Did not get the full size expected (wanted %d and "
212 "got %d bytes).", size_expected, full_length));
222 static bool garbage_initialized =
false;
227 if (!garbage_initialized) {
230 garbage_buffer[i] =
randomizer.inclusive(0, 255);
231 garbage_initialized =
true;
243 LOG(
"The size is over our limit. To fix this, edit the "
244 "send_data function.");
250 LOG(
"One cannot send data on an uninitialized tester!");
254 int runs_completed = 0;
257 while (runs_completed < count) {
258 #ifdef DEBUG_SPOCKET_TESTER
264 #ifdef DEBUG_SPOCKET_TESTER
265 LOG(
"client about to send");
267 if (!
do_a_send(garbage_buffer, size, stats)) {
268 LOG(
"We failed on a send. Now quitting.");
271 #ifdef DEBUG_SPOCKET_TESTER
272 LOG(
"client about to rcv");
275 LOG(
"We failed on a receive. Now quitting.");
282 #ifdef DEBUG_SPOCKET_TESTER
283 LOG(
"server about to rcv");
286 LOG(
"We failed on a receive. Now quitting.");
289 #ifdef DEBUG_SPOCKET_TESTER
290 LOG(
"server about to send");
292 if (!
do_a_send(garbage_buffer, size, stats)) {
293 LOG(
"We failed on a send. Now quitting.");
301 if ( !(runs_completed % 10) )
a_sprintf is a specialization of astring that provides printf style support.
Provides a dynamically resizable ASCII character string.
Outcomes describe the state of completion for an operation.
a platform-independent way to acquire random numbers in a specific range.
this type of address describes a destination out on the internet.
Abstraction for a higher-level BSD socket that is platform independent.
basis::outcome await_writable(int timeout)
basis::outcome send(const basis::abyte *buffer, int size, int &len_sent)
basis::outcome connect(int communication_wait=20 *basis::SECOND_ms)
basis::outcome accept(spocket *&sock, bool wait)
basis::outcome await_readable(int timeout)
basis::outcome receive(basis::abyte *buffer, int &size)
Helpful functions for interacting with TCP/IP stacks.
bool perform_test(int size, int count, testing_statistics &stats_to_fill)
bool accept(bool wait=true)
spocket_tester(const sockets::internet_address &where)
bool do_a_receive(int size_expected, testing_statistics &stats)
bool do_a_send(basis::abyte *buffer, int size, testing_statistics &stats)
Represents a point in time relative to the operating system startup time.
void reset()
sets the stamp time back to now.
time_representation value() const
returns the time_stamp in terms of the lower level type.
#define NULL_POINTER
The value representing a pointer to nothing.
The guards collection helps in testing preconditions and reporting errors.
void WHACK(contents *&ptr)
deletion with clearing of the pointer.
unsigned char abyte
A fairly important unit which is seldom defined...
const int SECOND_ms
Number of milliseconds in a second.
A logger that sends to the console screen using the standard output device.
An extension to floating point primitives providing approximate equality.
Provides access to the operating system's socket methods.
A dynamic container class that holds any kind of object via pointers.
const int MAXIMUM_WINSOCK_MTU
const int MAXIMUM_TRANSFER_WAIT