# module GxG::Support::Library::SocketIORecvFrom

### Public Instance Methods

recvfrom(max_mesg_length=nil, flags=0) click to toggle source

Note: Allow aliases or existing recvfrom_nonblock to catch method references. Do not define recvfrom_nonblock here.

    # File lib/gxg/gxg_io.rb, line 445
    def recvfrom(max_mesg_length=nil, flags=0)
      # for now, flags ignored.  LATER: study Socket.recv message flags in detail
      if self.fcntl(::Fcntl::F_GETFL,::Fcntl::O_NONBLOCK) & ::Fcntl::O_NONBLOCK == ::Fcntl::O_NONBLOCK
        # on Winderz, just to a buffer sized spoon full until done ??
        if self.closed?()
          raise IOError, "attempting to recvmsg on a closed stream"
        else
          if @before_receive_data.respond_to?(:call)
            @before_receive_data.call()
          end
          begin
            result = self.recvfrom_nonblock(max_mesg_length, flags)
            #
          rescue ::IO::WaitReadable, ::IO::WaitWritable, GxG::IO::IO::WaitReadable, GxG::IO::IO::WaitWritable
            pause
            begin
              # about 10 ms
              selected = GxG::IO::IO::select([self],nil,nil,0.010)
              until selected
                pause
                selected = GxG::IO::IO::select([self],nil,nil,0.010)
              end
            rescue Exception
              pause
              retry
            end
            retry
          end
          #
          if result.is_a?(::Array)
            if result[0].is_a?(::String)
              result[0].force_encoding(::Encoding::ASCII_8BIT)
            end
          end
          if @after_receive_data.respond_to?(:call)
            @after_receive_data.call(result)
          end
        end
      else
        if self.closed?()
          raise IOError, "attempting to recvmsg on a closed stream"
        else
          if @before_receive_data.respond_to?(:call)
            @before_receive_data.call()
          end
          result = self.original_recvfrom(max_mesg_length, flags)
          if result.is_a?(::Array)
            if result[0].is_a?(::String)
              result[0].force_encoding(::Encoding::ASCII_8BIT)
            end
          end
          if @after_receive_data.respond_to?(:call)
            @after_receive_data.call(result)
          end
        end
      end
      result
    end