parameters: (sock, b, buff_size)
return_statement: return decode_ros_handshake_header(bval)
docstring: Read in tcpros header off the socket \a sock using buffer \a b.
      
      :param sock: socket must be in blocking mode, ``socket``
      :param b: buffer to use, ``StringIO`` for Python2, ``BytesIO`` for Python 3
      :param buff_size: incoming buffer size to use, ``int``
      :returns: key value pairs encoded in handshake, ``{str: str}``
      :raises: :exc:`ROSHandshakeException` If header format does not match expected
docstring_summary: Read in tcpros header off the socket \a sock using buffer \a b.
      
      :param sock: socket must be in blocking mode, ``socket``
      :param b: buffer to use, ``StringIO`` for Python2, ``BytesIO`` for Python 3
      :param buff_size: incoming buffer size to use, ``int``
      :returns: key value pairs encoded in handshake, ``{str: str}``
      :raises: :exc:`ROSHandshakeException` If header format does not match expected
docstring_tokens: Read in tcpros header off the socket \ a sock using buffer \ a b . : param sock : socket must be in blocking mode socket : param b : buffer to use StringIO for Python2 BytesIO for Python 3 : param buff_size : incoming buffer size to use int : returns : key value pairs encoded in handshake { str : str } : raises : : exc : ROSHandshakeException If header format does not match expected
function: def read_ros_handshake_header(sock, b, buff_size):
      """
      Read in tcpros header off the socket \a sock using buffer \a b.
      
      :param sock: socket must be in blocking mode, ``socket``
      :param b: buffer to use, ``StringIO`` for Python2, ``BytesIO`` for Python 3
      :param buff_size: incoming buffer size to use, ``int``
      :returns: key value pairs encoded in handshake, ``{str: str}``
      :raises: :exc:`ROSHandshakeException` If header format does not match expected
      """
      header_str = None
      while not header_str:
          d = sock.recv(buff_size)
          if not d:
              raise ROSHandshakeException("connection from sender terminated before handshake header received. %s bytes were received. Please check sender for additional details."%b.tell())
          b.write(d)
          btell = b.tell()
          if btell > 4:
              # most likely we will get the full header in the first recv, so
              # not worth tiny optimizations possible here
              bval = b.getvalue()
              (size,) = struct.unpack('<I', bval[0:4])
              if btell - 4 >= size:
                  header_str = bval
                      
                  # memmove the remnants of the buffer back to the start
                  leftovers = bval[size+4:]
                  b.truncate(len(leftovers))
                  b.seek(0)
                  b.write(leftovers)
                  header_recvd = True
                      
      # process the header
      return decode_ros_handshake_header(bval)
function_tokens: def read_ros_handshake_header ( sock , b , buff_size ) : header_str = None while not header_str : d = sock . recv ( buff_size ) if not d : raise ROSHandshakeException ( "connection from sender terminated before handshake header received. %s bytes were received. Please check sender for additional details." % b . tell ( ) ) b . write ( d ) btell = b . tell ( ) if btell > 4 : # most likely we will get the full header in the first recv, so # not worth tiny optimizations possible here bval = b . getvalue ( ) ( size , ) = struct . unpack ( '<I' , bval [ 0 : 4 ] ) if btell - 4 >= size : header_str = bval # memmove the remnants of the buffer back to the start leftovers = bval [ size + 4 : ] b . truncate ( len ( leftovers ) ) b . seek ( 0 ) b . write ( leftovers ) header_recvd = True # process the header return decode_ros_handshake_header ( bval )