package xturbo import "time" // InternAtoms interns every name in one pipelined batch and blocks for one // round trip (Sync), writing the atom of names[i] into dst[i] (0 for a name // that does not exist when onlyIfExists is set). len(dst) must equal // len(names) and every name be at most 65535 bytes (ErrBadLength, nothing // sent, the connection unaffected). The first X error on one of these // requests is returned as *XError, its Args[0] the index of the name; the // other atoms are still filled. Packets read meanwhile go to the last Handler // given to Dispatch. Like Sync it gives up after 5 s (os.ErrDeadlineExceeded). // Meant for startup; it must not be called from a Handler callback. func (c *Conn) InternAtoms(names []string, onlyIfExists bool, dst []uint32) error { if len(names) != len(dst) { return ErrBadLength } for _, name := range names { if len(name) > 0xffff { return ErrBadLength // a caller bug: fail before queuing anything } } if c.dispatching { return errReentrantDispatch } if c.fd < 0 { return ErrClosed } clear(dst) c.atoms = dst defer func() { c.atoms = nil }() deadline := time.Now().Add(c.timeout) c.syncFailed = false for i, name := range names { if err := c.waitSlot(deadline); err != nil { return err } seq := encodeInternAtom(c.buf, onlyIfExists, name) if seq == 0 { return c.buf.Err() } if err := c.expect(seq, kindInternAtom, [4]uint32{uint32(i)}); err != nil { return err } } if err := c.waitUntil(c.h, deadline); err != nil { return err } if c.syncFailed { e := c.syncErr return &e } return nil }