37b6f2328a
The handling of async IO on Windows wrongly casted everything to a socket connection. For named pipe based connections this caused reading of invalid memory. Moved some of the functions to a common superclass and only call showdown for socket connections. For named pipe based connections the Dart part of the code will never send shutdown commands as named pipe based connections start out being closed in one direction and closing the other direction causes a close command. R=ager@google.com BUG=dart:363 TEST= Review URL: http://codereview.chromium.org//8503006 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1308 260f80e4-7a28-3924-810f-c04153c831b5
61 lines
1.6 KiB
C++
61 lines
1.6 KiB
C++
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
/*
|
|
* Run ./process_test <outstream> <echocount> <exitcode> <crash>
|
|
* <outstream>: 0 = stdout, 1 = stderr, 2 = stdout and stderr
|
|
* <echocount>: program terminates after <echocount> replies
|
|
* <exitcode>: program terminates with exit code <exitcode>
|
|
* <crash>: 0 = program terminates regularly, 1 = program segfaults
|
|
*/
|
|
int main(int argc, char* argv[]) {
|
|
if (argc != 5) {
|
|
fprintf(stderr,
|
|
"./process_test <outstream> <echocount> <exitcode> <crash>\n");
|
|
exit(1);
|
|
}
|
|
|
|
int outstream = atoi(argv[1]);
|
|
if (outstream < 0 || outstream > 2) {
|
|
fprintf(stderr, "unknown outstream");
|
|
exit(1);
|
|
}
|
|
|
|
int echo_counter = 0;
|
|
int echo_count = atoi(argv[2]);
|
|
int exit_code = atoi(argv[3]);
|
|
int crash = atoi(argv[4]);
|
|
|
|
const int kLineSize = 128;
|
|
char line[kLineSize];
|
|
|
|
while ((echo_count != echo_counter) &&
|
|
(fgets(line, kLineSize, stdin) != NULL)) {
|
|
if (outstream == 0) {
|
|
fprintf(stdout, "%s", line);
|
|
fflush(stdout);
|
|
} else if (outstream == 1) {
|
|
fprintf(stderr, "%s", line);
|
|
fflush(stderr);
|
|
} else if (outstream == 2) {
|
|
fprintf(stdout, "%s", line);
|
|
fprintf(stderr, "%s", line);
|
|
fflush(stdout);
|
|
fflush(stderr);
|
|
}
|
|
echo_counter++;
|
|
}
|
|
|
|
if (crash == 1) {
|
|
int* segfault = NULL;
|
|
*segfault = 1;
|
|
}
|
|
|
|
return exit_code;
|
|
}
|