summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2009-05-19 23:31:55 +0200
committerVolker Lendecke <vl@samba.org>2009-05-19 23:35:16 +0200
commitf9d00fb58e8e9fed24751ad26dbdbc394f30290e (patch)
tree4aa6e8abcae1d5e782d771f3be26dc201c2a9eeb
parentcf9636ea99bb5063a8c7d771c1e29f684b4b753a (diff)
downloadsamba-f9d00fb58e8e9fed24751ad26dbdbc394f30290e.tar.gz
samba-f9d00fb58e8e9fed24751ad26dbdbc394f30290e.tar.bz2
samba-f9d00fb58e8e9fed24751ad26dbdbc394f30290e.zip
Simplify the logic of tsocket_bsd_pending
Remove two indentation levels by returning early on error. Metze, please check!
-rw-r--r--lib/tsocket/tsocket_bsd.c50
1 files changed, 26 insertions, 24 deletions
diff --git a/lib/tsocket/tsocket_bsd.c b/lib/tsocket/tsocket_bsd.c
index 0ec47f8466..054bb3de3a 100644
--- a/lib/tsocket/tsocket_bsd.c
+++ b/lib/tsocket/tsocket_bsd.c
@@ -149,40 +149,42 @@ static int tsocket_bsd_common_prepare_fd(int fd, bool high_fd)
static ssize_t tsocket_bsd_pending(int fd)
{
- int ret;
+ int ret, error;
int value = 0;
+ socklen_t len;
ret = ioctl(fd, FIONREAD, &value);
if (ret == -1) {
return ret;
}
- if (ret == 0) {
- if (value == 0) {
- int error=0;
- socklen_t len = sizeof(error);
- /*
- * if no data is available check if the socket
- * is in error state. For dgram sockets
- * it's the way to return ICMP error messages
- * of connected sockets to the caller.
- */
- ret = getsockopt(fd, SOL_SOCKET, SO_ERROR,
- &error, &len);
- if (ret == -1) {
- return ret;
- }
- if (error != 0) {
- errno = error;
- return -1;
- }
- }
+ if (ret != 0) {
+ /* this should not be reached */
+ errno = EIO;
+ return -1;
+ }
+
+ if (value != 0) {
return value;
}
- /* this should not be reached */
- errno = EIO;
- return -1;
+ error = 0;
+ len = sizeof(error);
+
+ /*
+ * if no data is available check if the socket is in error state. For
+ * dgram sockets it's the way to return ICMP error messages of
+ * connected sockets to the caller.
+ */
+ ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len);
+ if (ret == -1) {
+ return ret;
+ }
+ if (error != 0) {
+ errno = error;
+ return -1;
+ }
+ return 0;
}
static const struct tsocket_address_ops tsocket_address_bsd_ops;