From f66955f7250d7c150dfb97862878acc2222781e5 Mon Sep 17 00:00:00 2001 From: walter harms Date: Fri, 8 Sep 2017 20:03:03 +0200 Subject: make IceProtocolShutdown() more readable I found IceProtocolShutdown() hard to read only to find that was it does it aktually very simple. So i rearranged the code to make it more readable. Signed-off-by: Walter Harms Reviewed-by: Eric Engestrom [Emil Velikov: whitespace fixes] Signed-off-by: Emil Velikov --- src/shutdown.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/src/shutdown.c b/src/shutdown.c index 3f0880b..f27c876 100644 --- a/src/shutdown.c +++ b/src/shutdown.c @@ -40,45 +40,37 @@ IceProtocolShutdown ( int majorOpcode ) { + int i; + if (iceConn->proto_ref_count == 0 || iceConn->process_msg_info == NULL || majorOpcode < 1 || majorOpcode > _IceLastMajorOpcode) { return (0); } - else - { - /* - * Make sure this majorOpcode is really being used. - */ - int i; - for (i = iceConn->his_min_opcode; i <= iceConn->his_max_opcode; i++) - { - if (iceConn->process_msg_info[ - i - iceConn->his_min_opcode].in_use && - iceConn->process_msg_info[ - i - iceConn->his_min_opcode].my_opcode == majorOpcode) - break; - } + /* + * Make sure this majorOpcode is really being used. + */ - if (i > iceConn->his_max_opcode) - { - return (0); - } - else + for (i = iceConn->his_min_opcode; i <= iceConn->his_max_opcode; i++) + { + int n = i - iceConn->his_min_opcode; + if (iceConn->process_msg_info[n].in_use && + iceConn->process_msg_info[n].my_opcode == majorOpcode) { + /* * OK, we can shut down the protocol. */ - iceConn->process_msg_info[ - i - iceConn->his_min_opcode].in_use = False; + iceConn->process_msg_info[n].in_use = False; iceConn->proto_ref_count--; - return (1); } } + + return (0); } -- cgit v1.2.3