34 using namespace basis;
42 #define LOG(to_print) EMERGENCY_LOG(program_wide_logger().get(), astring(to_print))
77 if (_ucast) type = spocket::UNICAST;
79 _socket =
new spocket(*_where, type);
82 return ret == spocket::OKAY;
93 #ifdef DEBUG_SPOCKET_TESTER
98 worked = _socket->
send_to(where_to, buffer, size, len_sent);
99 if (worked == spocket::NONE_READY) {
100 time_control::sleep_ms(20);
102 }
else if (worked == spocket::PARTIAL) {
106 time_control::sleep_ms(20);
110 #ifdef DEBUG_SPOCKET_TESTER
111 LOG(
"got out of loop");
116 if ( (worked != spocket::OKAY) || !len_sent) {
117 LOG(
"No data went out on the socket.");
120 if (len_sent != size) {
121 LOG(
a_sprintf(
"The full chunk didn't get sent out: %d bytes instead of %d",
139 #ifdef DEBUG_SPOCKET_TESTER
140 LOG(
"into do a rcv");
145 while ( (full_length < size_expected) && (
time_stamp() < when_to_leave) ) {
151 if (ret != spocket::OKAY) {
152 if (ret == spocket::NONE_READY) {
153 time_control::sleep_ms(20);
158 if (ret == spocket::OKAY)
161 int receive_duration = int(
time_stamp().value()
162 - start_of_receive.
value());
165 #ifdef DEBUG_SPOCKET_TESTER
170 LOG(
"Our socket has been disconnected.");
172 }
else if (len < 0) {
174 LOG(
astring(
"The receive failed with an error ")
175 + critical_events::system_error_text(errno));
182 if (full_length != size_expected)
183 LOG(
a_sprintf(
"Did not get the full size expected (wanted %d and "
184 "got %d bytes).", size_expected, full_length));
192 #ifdef DEBUG_SPOCKET_TESTER
193 LOG(
"into perf test");
198 static bool garbage_initialized =
false;
203 if (!garbage_initialized) {
206 garbage_buffer[i] =
randomizer.inclusive(0, 255);
207 garbage_initialized =
true;
219 LOG(
"The size is over our limit. To fix this, edit the "
220 "send_data function.");
226 LOG(
"One cannot send data on an uninitialized tester!");
230 int runs_completed = 0;
233 while (runs_completed < count) {
234 #ifdef DEBUG_SPOCKET_TESTER
239 #ifdef DEBUG_SPOCKET_TESTER
240 LOG(
"client about to send");
242 if (!
do_a_send(dest, garbage_buffer, size, stats)) {
243 LOG(
"We failed on a send. Now quitting.");
246 #ifdef DEBUG_SPOCKET_TESTER
247 LOG(
"client about to rcv");
250 LOG(
"We failed on a receive. Now quitting.");
257 if ( !(runs_completed % 10) )
const int MAXIMUM_WINSOCK_MTU
const int MAXIMUM_TRANSFER_WAIT
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.
~broadcast_spocket_tester()
bool do_a_send(const sockets::internet_address &where_to, basis::abyte *buffer, int size, testing_statistics &stats)
bool perform_test(const sockets::internet_address &dest, int size, int count, testing_statistics &stats_to_fill)
broadcast_spocket_tester(const sockets::internet_address &where, bool unicast=false)
bool do_a_receive(int size_expected, testing_statistics &stats)
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 connect(int communication_wait=20 *basis::SECOND_ms)
basis::outcome receive_from(basis::abyte *buffer, int &size, internet_address &where_from)
basis::outcome send_to(const internet_address &where_to, const basis::abyte *buffer, int size, int &len_sent)
Helpful functions for interacting with TCP/IP stacks.
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.
Useful support functions for unit testing, especially within hoople.