Skip to content

Commit f08b6a1

Browse files
Merge pull request #92 from kevinGC/reuseaddr2
add --reuseaddr to rr binaries
2 parents 3362608 + 9c84503 commit f08b6a1

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

define_all_flags.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ struct flags_parser *add_flags_common(struct flags_parser *fp)
4747
DEFINE_FLAG(fp, double, interval, 1.0, 'I', "For how many seconds that a sample is generated");
4848
DEFINE_FLAG(fp, long long, max_pacing_rate, 0, 'm', "SO_MAX_PACING_RATE value; use as 64-bit unsigned");
4949
DEFINE_FLAG_PARSER(fp, max_pacing_rate, parse_max_pacing_rate);
50-
DEFINE_FLAG(fp, int, mark, 0, 'M', "SO_MARK value; use as 32-bit unsigned");
5150
DEFINE_FLAG(fp, const char *, local_hosts, NULL, 'L', "Local hostnames or IP addresses");
5251
DEFINE_FLAG(fp, const char *, host, NULL, 'H', "Server hostname or IP address");
5352
DEFINE_FLAG(fp, const char *, control_port, "12866", 'C', "Server control port");
@@ -96,6 +95,7 @@ struct flags_parser *add_flags_rr(struct flags_parser *fp)
9695
DEFINE_FLAG_PRINTER(fp, percentiles, percentiles_print);
9796
DEFINE_FLAG(fp, int, test_length, 10, 'l', "Test length, >0 seconds, <0 transactions");
9897
DEFINE_FLAG(fp, int, buffer_size, 65536, 'B', "Number of bytes that each read()/send() can transfer at once");
98+
DEFINE_FLAG(fp, int, mark, 0, 0, "SO_MARK value; use as 32-bit unsigned");
9999

100100
/* Return the updated fp */
101101
return (fp);
@@ -122,6 +122,7 @@ struct flags_parser *add_flags_tcp_rr(struct flags_parser *fp)
122122
DEFINE_FLAG(fp, unsigned long, delay, 0, 'D', "Delay between each send()/write() in ns (default), us, ms, or s");
123123
DEFINE_FLAG_PARSER(fp, delay, parse_duration);
124124
DEFINE_FLAG(fp, bool, async_connect, false, 0, "use non blocking connect");
125+
DEFINE_FLAG(fp, bool, reuseaddr, false, 0, "Use SO_REUSEADDR on sockets");
125126
DEFINE_FLAG(fp, unsigned long, noburst, 0, 0, "noburst interval in ns (default), us, ms, or s");
126127
DEFINE_FLAG_PARSER(fp, noburst, parse_duration);
127128

@@ -151,6 +152,7 @@ struct flags_parser *add_flags_tcp_stream(struct flags_parser *fp)
151152
DEFINE_FLAG(fp, bool, enable_tcp_maerts, false, 'M', "Enables TCP_MAERTS test (server writes and client reads). It overrides enable_read, and enable_write");
152153
DEFINE_FLAG(fp, bool, async_connect, false, 0, "use non blocking connect");
153154
DEFINE_FLAG(fp, bool, no_cork, false, 0, "Do not set MSG_MORE when sending over data sockets.");
155+
DEFINE_FLAG(fp, int, mark, 0, 'M', "SO_MARK value; use as 32-bit unsigned");
154156

155157
/* Return the updated fp */
156158
return (fp);
@@ -170,6 +172,7 @@ struct flags_parser *add_flags_udp_stream(struct flags_parser *fp)
170172
/* Define flags specialized to only UDP_STREAM */
171173
DEFINE_FLAG(fp, unsigned long, delay, 0, 'D', "Nanosecond delay between each send()/write()");
172174
DEFINE_FLAG(fp, int, buffer_size, 1400, 'B', "Number of bytes that each read/write uses as the buffer");
175+
DEFINE_FLAG(fp, int, mark, 0, 'M', "SO_MARK value; use as 32-bit unsigned");
173176

174177
/* Return the updated fp */
175178
return (fp);

flags.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct flags_parser {
4545
struct flag *flags;
4646
bool help;
4747
bool version;
48+
char short_names[32];
4849
};
4950

5051
static void flag_destroy(struct flag *flag)
@@ -103,6 +104,18 @@ void flags_parser_add(struct flags_parser *fp, char short_name,
103104
{
104105
struct flag *flag;
105106

107+
/* Ensure we don't clobber another flag's name. We only check the short
108+
* name, as the long_name is derived directly from a struct field. So if
109+
* two flags set it, they're just rendundant, not broken.
110+
*/
111+
int index = short_name / 8;
112+
char bit = 1 << (short_name & 7);
113+
if (short_name != 0 && fp->short_names[index]&bit)
114+
LOG_FATAL(fp->cb, "error: flag short name %c set twice",
115+
short_name);
116+
fp->short_names[index] |= bit;
117+
118+
106119
flag = calloc(1, sizeof(*flag));
107120
if (!flag)
108121
LOG_FATAL(fp->cb, "calloc flag");

logging.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ static void open_log(void)
7474
if (log_file)
7575
fclose(log_file);
7676
log_file = fopen(path, "w");
77+
if (!log_file) {
78+
printf("failed to open log file \"%s\" (error %s). "
79+
"This happens often with blaze run, in which "
80+
"case try using --logtostderr or --nolog\n",
81+
path, strerror(errno));
82+
fflush(stdout);
83+
fflush(stderr);
84+
exit(1);
85+
}
7786
}
7887

7988
static void close_log(void)

0 commit comments

Comments
 (0)