summaryrefslogtreecommitdiff
path: root/lib/socket-util.c
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2010-11-09 15:36:48 -0800
committerBen Pfaff <blp@nicira.com>2010-11-10 10:56:01 -0800
commite61c056cb94aeffc86cb314ea32726be9b666724 (patch)
tree56e415f3e91d01ad156a2f4b671b4c32ebc08d6b /lib/socket-util.c
parente1aff6f9f7103ee59e2501d3e6c705a685b20aeb (diff)
downloadopenvswitch-e61c056cb94aeffc86cb314ea32726be9b666724.tar.gz
socket-util: Define LINUX macro at top of file.
This will be used further in the following commit.
Diffstat (limited to 'lib/socket-util.c')
-rw-r--r--lib/socket-util.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/socket-util.c b/lib/socket-util.c
index 573e28f1a..8d291edb4 100644
--- a/lib/socket-util.c
+++ b/lib/socket-util.c
@@ -36,6 +36,15 @@
VLOG_DEFINE_THIS_MODULE(socket_util);
+/* #ifdefs make it a pain to maintain code: you have to try to build both ways.
+ * Thus, this file compiles all of the code regardless of the target, by
+ * writing "if (LINUX)" instead of "#ifdef __linux__". */
+#ifdef __linux__
+#define LINUX 1
+#else
+#define LINUX 0
+#endif
+
/* Sets 'fd' to non-blocking mode. Returns 0 if successful, otherwise a
* positive errno value. */
int
@@ -171,12 +180,7 @@ drain_rcvbuf(int fd)
*
* On other Unix-like OSes, MSG_TRUNC has no effect in the flags
* argument. */
-#ifdef __linux__
-#define BUFFER_SIZE 1
-#else
-#define BUFFER_SIZE 2048
-#endif
- char buffer[BUFFER_SIZE];
+ char buffer[LINUX ? 1 : 2048];
ssize_t n_bytes = recv(fd, buffer, sizeof buffer,
MSG_TRUNC | MSG_DONTWAIT);
if (n_bytes <= 0 || n_bytes >= rcvbuf) {