mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-06 15:51:25 +00:00
Add missing BSD functions
This commit is contained in:
1 parent
7886a73807
commit
66afa5e551
6 files changed
+646
-39
No files matched your search
+11
-2
@@ -92,7 +92,7 @@ fail:
|
||||
exit(1);
|
||||
}
|
||||
|
||||
enum wait_mode { WAIT_ABORT, WAIT_DRAIN, WAIT_HOLD, WAIT_CLOSE };
|
||||
enum wait_mode { WAIT_ABORT, WAIT_DRAIN, WAIT_HOLD, WAIT_CLOSE, WAIT_SEND };
|
||||
|
||||
// Wait for output, optionally draining through the final marker.
|
||||
static int wait_data(const char *host, enum wait_mode mode) {
|
||||
@@ -117,6 +117,13 @@ static int wait_data(const char *host, enum wait_mode mode) {
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
if (mode == WAIT_SEND) {
|
||||
usleep(100000); // Let the server shut down its read side
|
||||
n = send(fd, "x", 1, 0);
|
||||
usleep(500000); // Keep peer connected for server SHUT_WR
|
||||
close(fd);
|
||||
return n == 1 ? 0 : 1;
|
||||
}
|
||||
if (mode == WAIT_CLOSE) {
|
||||
n = recv(fd, buf, sizeof(buf), 0);
|
||||
close(fd);
|
||||
@@ -151,10 +158,12 @@ int main(int argc, char *argv[]) {
|
||||
return wait_data(argv[1], WAIT_HOLD);
|
||||
if (argc == 3 && strcmp(argv[2], "expectclose") == 0)
|
||||
return wait_data(argv[1], WAIT_CLOSE);
|
||||
if (argc == 3 && strcmp(argv[2], "sendlater") == 0)
|
||||
return wait_data(argv[1], WAIT_SEND);
|
||||
if (argc == 3) connections = atoi(argv[2]);
|
||||
if ((argc != 2 && argc != 3) || connections < 1 ||
|
||||
connections > NUM_CONNECTIONS) {
|
||||
fprintf(stderr, "usage: %s IP [connections|waitandabort|waitanddrain|hold|expectclose]\n",
|
||||
fprintf(stderr, "usage: %s IP [connections|waitandabort|waitanddrain|hold|expectclose|sendlater]\n",
|
||||
argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user