Class: UDPSocket

Inherits:
IPSocket show all
Defined in:
lib/polyphony/extensions/socket.rb

Overview

UDPSocket extensions

Instance Method Summary collapse

Instance Method Details

#recvfrom(maxlen, flags = 0) ⇒ String

Reimplements #recvfrom.

Parameters:

  • maxlen (Integer)

    maximum bytes to receive

  • flags (Integer) (defaults to: 0)

    optional flags

Returns:

  • (String)

    received data



668
669
670
671
# File 'lib/polyphony/extensions/socket.rb', line 668

def recvfrom(maxlen, flags = 0)
  buf = +''
  Polyphony.backend_recvmsg(self, buf, maxlen, 0, flags, 0, nil)
end

#recvmsg(maxlen = nil, flags = 0, maxcontrollen = nil, opts = {}) ⇒ String

Reimplements #recvmsg.

Parameters:

  • maxlen (Integer) (defaults to: nil)

    maximum bytes to receive

  • flags (Integer) (defaults to: 0)

    optional flags

  • maxcontrollen (Integer) (defaults to: nil)

    maximum control bytes to receive

  • opts (Hash) (defaults to: {})

    options

Returns:

  • (String)

    received data



680
681
682
683
# File 'lib/polyphony/extensions/socket.rb', line 680

def recvmsg(maxlen = nil, flags = 0, maxcontrollen = nil, opts = {})
  buf = +''
  Polyphony.backend_recvmsg(self, buf, maxlen || 4096, 0, flags, maxcontrollen, opts)
end

#send(msg, flags, *addr) ⇒ Integer

Sends data.

Parameters:

  • msg (String)

    data to send

  • flags (Integer)

    flags

  • addr (Array)

    addresses to send to

Returns:

  • (Integer)

    bytes sent



702
703
704
705
706
707
708
709
710
711
712
713
# File 'lib/polyphony/extensions/socket.rb', line 702

def send(msg, flags, *addr)
  sockaddr =  case addr.size
              when 2
                Socket.sockaddr_in(addr[1], addr[0])
              when 1
                addr[0]
              else
                nil
              end

  Polyphony.backend_sendmsg(self, msg, flags, sockaddr, nil)
end

#sendmsg(msg, flags = 0, dest_sockaddr = nil, *controls) ⇒ Integer

Reimplements #sendmsg.

Parameters:

  • msg (String)

    data to send

  • flags (Integer) (defaults to: 0)

    optional flags

  • dest_sockaddr (Sockaddr, nil) (defaults to: nil)

    optional destination address

  • controls (Array)

    optional control data

Returns:

  • (Integer)

    bytes sent



692
693
694
# File 'lib/polyphony/extensions/socket.rb', line 692

def sendmsg(msg, flags = 0, dest_sockaddr = nil, *controls)
  Polyphony.backend_sendmsg(self, msg, flags, dest_sockaddr, controls)
end