FAQ
Hello,

I want to read a socket's error queue and cannot find a way to do that
for an UDPConn.

I am trying to implement a traceroute-like utility in Go. In order to
do that I would like to open an UDP socket, send some packets, and
read the error queue of the socket. At least on Linux, the last is
achieved by recvmsg(MSG_ERRQUEUE) on a socket that had IP_RECVERR flag
set. There are two problems with this approach: UDPConn.ReadMsgUDP
doesn't allow one to pass flags to runtime.Recvmsg (it always passes
0) and I'm not sure if setting IP_RECVERR on a duplicate fd (returned
by UDPConn.File()) would have the desired effect.

I don't know if other operating systems implement a mechanism to
retrieve errors in some similar fashion (recvmsg(MSG_ERRQUEUE) isn't
in Posix and in fact, it doesn't seem to say anything about error
queues), but I'd assume it'd be significantly different.

It seems that in order to solve my problem on Linux without any
modifications to Go, I would need to use syscall package directly and
either do a lot of blocking syscalls or use a separate instance of
some kind of poll server. Would adding a way to call ReadMsg with
flags be reasonable?

Robert

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Mikio Hara at Feb 28, 2013 at 1:58 am
    Hi,
    On Mon, Feb 25, 2013 at 1:15 AM, Robert wrote:

    It seems that in order to solve my problem on Linux without any
    modifications to Go, I would need to use syscall package directly and
    either do a lot of blocking syscalls or use a separate instance of
    some kind of poll server.
    Yes, at least under the Go 1 contract.
    Would adding a way to call ReadMsg with flags be reasonable?
    And WriteMsg too? Not sure, but Read/WriteMsgIP, UDP methods
    are new API for Go 1.1. I think you can contribute a bugfix patch
    until Go 1.1 cutoff if you think that's an API design bug.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Robert Obryk at Feb 28, 2013 at 1:37 pm
    +cc golang-dev
    +bcc golang-nuts

    Hello,

    I would like to propose a change in the net package in the
    {Read,Write}Msg* methods (they are to be new in Go1.1), so that they
    allow flags to be passed in. As far as I know, the only way to read a
    socket's error queue in Linux is to use recvmsg with MSG_ERRQUEUE flag
    set. The {Read,Write}Msg methods don't allow flags to be passed in and
    set them always to 0.

    I propose that both ReadMsg* and WriteMsg* take an additional argument
    for flags. This obviously exports system-specific flags out of the net
    package, but we already do that in the other direction in these same
    methods. ReadMsg should filter out MSG_WAITALL (because it seems
    nonsensical or poorly defined for nonblocking operations); all other
    flags from POSIX and Linux-specific ones seem not to interfere with
    the assumptions related to the poll server or nonblocking behaviour. I
    also propose that ReadMsgUnix set MSG_CMSG_CLOEXEC, for similar
    reasons we set O_CLOEXEC in open() (although I'm not sure if that
    shouldn't be the domain of someone who actually uses SCM_RIGHTS). For
    WriteMsg* I didn't find any flags that would seem to interfere with
    assumptions related to the poll server and nonblocking behaviour.

    I will send a CL upon request; I didn't do it first because the
    contributing guidelines strongly advise against that. This is a change
    that, as far as I understand the backwards compatibility guarantees,
    should be made before Go1.1 or not at all in the foreseeable future.

    Robert
    On Thu, Feb 28, 2013 at 2:58 AM, Mikio Hara wrote:
    Would adding a way to call ReadMsg with flags be reasonable?
    And WriteMsg too? Not sure, but Read/WriteMsgIP, UDP methods
    are new API for Go 1.1. I think you can contribute a bugfix patch
    until Go 1.1 cutoff if you think that's an API design bug.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedFeb 24, '13 at 5:41p
activeFeb 28, '13 at 1:37p
posts3
users2
websitegolang.org

2 users in discussion

Robert Obryk: 2 posts Mikio Hara: 1 post

People

Translate

site design / logo © 2021 Grokbase