1
0

debug: attempt to make the simulation deterministic by not returning until connection is made and command is receieved

This commit is contained in:
Megan Wachs 2017-11-21 15:46:44 -08:00
parent 1d3fa07c44
commit 024cd52c44

View File

@ -78,20 +78,23 @@ void remote_bitbang_t::accept()
{ {
fprintf(stderr,"Attempting to accept client socket\n"); fprintf(stderr,"Attempting to accept client socket\n");
int again = 1;
while (again != 0) {
client_fd = ::accept(socket_fd, NULL, NULL); client_fd = ::accept(socket_fd, NULL, NULL);
if (client_fd == -1) { if (client_fd == -1) {
if (errno == EAGAIN) { if (errno == EAGAIN) {
// No client waiting to connect right now. // No client waiting to connect right now.
fprintf(stderr, "Not Accepted: Received EAGAIN error\n");
} else { } else {
fprintf(stderr, "failed to accept on socket: %s (%d)\n", strerror(errno), fprintf(stderr, "failed to accept on socket: %s (%d)\n", strerror(errno),
errno); errno);
again = 0;
abort(); abort();
} }
} else { } else {
fcntl(client_fd, F_SETFL, O_NONBLOCK); fcntl(client_fd, F_SETFL, O_NONBLOCK);
fprintf(stderr, "Accepted successfully."); fprintf(stderr, "Accepted successfully.");
again = 0;
}
} }
} }
@ -130,23 +133,25 @@ void remote_bitbang_t::set_pins(char _tck, char _tms, char _tdi){
void remote_bitbang_t::execute_command() void remote_bitbang_t::execute_command()
{ {
char command; char command;
int again = 1;
while (again) {
ssize_t num_read = read(client_fd, &command, sizeof(command)); ssize_t num_read = read(client_fd, &command, sizeof(command));
if (num_read == -1) { if (num_read == -1) {
if (errno == EAGAIN) { if (errno == EAGAIN) {
// We'll try again the next call. // We'll try again the next call.
fprintf(stderr, "Received no command. Will try again on the next call\n"); fprintf(stderr, "Received no command. Will try again on the next call\n");
return;
} else { } else {
fprintf(stderr, "remote_bitbang failed to read on socket: %s (%d)\n", fprintf(stderr, "remote_bitbang failed to read on socket: %s (%d)\n",
strerror(errno), errno); strerror(errno), errno);
again = 0;
abort(); abort();
} }
} } else if (num_read == 0) {
if (num_read == 0) {
fprintf(stderr, "No Command Received.\n"); fprintf(stderr, "No Command Received.\n");
return; again = 1;
} else {
again = 0;
}
} }
fprintf(stderr, "Received a command %c\n", command); fprintf(stderr, "Received a command %c\n", command);