Skip to content

Commit

Permalink
Fixed problems with connect() implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
smuehlst committed Feb 25, 2024
1 parent 66009b9 commit 03d6089
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/smoketest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,5 @@ jobs:
./socket_test.sh &
# Guard against endless loop in QEMU run (120 CPU secs)
ulimit -t 120
$CFG_QEMU_BIN -M ${{ matrix.config.qemu-machine }} $CFG_QEMU_OPT $CFG_QEMU_IMG -display none -nographic -semihosting -sd sdcard.img -netdev user,id=net0,hostfwd=tcp::5000-:5000 -device usb-net,netdev=net0
# Run QEMU with simulated network
$CFG_QEMU_BIN -M ${{ matrix.config.qemu-machine }} $CFG_QEMU_OPT $CFG_QEMU_IMG -display none -nographic -semihosting -sd sdcard.img -netdev \"user,id=net0,hostfwd=tcp::5000-:5000,guestfwd=tcp:10.0.2.100:5001-cmd:yes simulated server\" -device usb-net,netdev=net0
2 changes: 1 addition & 1 deletion libs/circle-newlib
9 changes: 4 additions & 5 deletions samples/05-smoketest/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -908,8 +908,6 @@ void CKernel::SocketTest(void)
PErrorExit("close (fd) failed");
}

#if 0
// TODO this attempt to use connect() hangs.
fd = socket(AF_INET, SOCK_STREAM, 0);

if (fd == -1)
Expand All @@ -936,25 +934,26 @@ void CKernel::SocketTest(void)
read_result = read(fd, buffer, sizeof(buffer));
if (read_result < 0)
{
PErrorExit("connect() failed");
PErrorExit("read() failed after connect");
}

Report("Read %d bytes from server", read_result);

char const expected_data[] = "simulated server";
if (strncmp(buffer, expected_data, sizeof(expected_data) - 1) != 0)
{
Report("read() from socket returned unexpeted data");
Report("read() from socket returned unexpected data");
exit(1);
}

Report("Received expected data from server");

if (close(fd) < 0)
{
PErrorExit("close (fd) failed");
}

Report("Read from client connection successful");
#endif
}

Report("Basic socket lifecycle test successful");
Expand Down
4 changes: 0 additions & 4 deletions samples/05-smoketest/socket_test.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/bash

# echo "Starting socat server in the background"

#socat -U TCP4-LISTEN:5001 "EXEC:yes socat server" &

echo "Waiting for QEMU to open socket 5000..."

while ! nc -z localhost 5000; do
Expand Down

0 comments on commit 03d6089

Please sign in to comment.