id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens listlengths 21 1.41k | docstring stringlengths 6 2.61k | docstring_tokens listlengths 3 215 | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
132,000 | 256dpi/gomqtt | session/packet_store.go | NewPacketStoreWithPackets | func NewPacketStoreWithPackets(packets []packet.Generic) *PacketStore {
// prepare store
store := &PacketStore{
packets: make(map[packet.ID]packet.Generic),
}
// add packets
for _, pkt := range packets {
store.Save(pkt)
}
return store
} | go | func NewPacketStoreWithPackets(packets []packet.Generic) *PacketStore {
// prepare store
store := &PacketStore{
packets: make(map[packet.ID]packet.Generic),
}
// add packets
for _, pkt := range packets {
store.Save(pkt)
}
return store
} | [
"func",
"NewPacketStoreWithPackets",
"(",
"packets",
"[",
"]",
"packet",
".",
"Generic",
")",
"*",
"PacketStore",
"{",
"// prepare store",
"store",
":=",
"&",
"PacketStore",
"{",
"packets",
":",
"make",
"(",
"map",
"[",
"packet",
".",
"ID",
"]",
"packet",
... | // NewPacketStoreWithPackets returns a new PacketStore with the provided packets. | [
"NewPacketStoreWithPackets",
"returns",
"a",
"new",
"PacketStore",
"with",
"the",
"provided",
"packets",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/session/packet_store.go#L23-L35 |
132,001 | 256dpi/gomqtt | session/packet_store.go | Save | func (s *PacketStore) Save(pkt packet.Generic) {
s.mutex.Lock()
defer s.mutex.Unlock()
id, ok := packet.GetID(pkt)
if ok {
s.packets[id] = pkt
}
} | go | func (s *PacketStore) Save(pkt packet.Generic) {
s.mutex.Lock()
defer s.mutex.Unlock()
id, ok := packet.GetID(pkt)
if ok {
s.packets[id] = pkt
}
} | [
"func",
"(",
"s",
"*",
"PacketStore",
")",
"Save",
"(",
"pkt",
"packet",
".",
"Generic",
")",
"{",
"s",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"id",
",",
"ok",
":=",
"packet",
"."... | // Save will store a packet in the store. An eventual existing packet with the
// same id gets quietly overwritten. | [
"Save",
"will",
"store",
"a",
"packet",
"in",
"the",
"store",
".",
"An",
"eventual",
"existing",
"packet",
"with",
"the",
"same",
"id",
"gets",
"quietly",
"overwritten",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/session/packet_store.go#L39-L47 |
132,002 | 256dpi/gomqtt | session/packet_store.go | Lookup | func (s *PacketStore) Lookup(id packet.ID) packet.Generic {
s.mutex.RLock()
defer s.mutex.RUnlock()
return s.packets[id]
} | go | func (s *PacketStore) Lookup(id packet.ID) packet.Generic {
s.mutex.RLock()
defer s.mutex.RUnlock()
return s.packets[id]
} | [
"func",
"(",
"s",
"*",
"PacketStore",
")",
"Lookup",
"(",
"id",
"packet",
".",
"ID",
")",
"packet",
".",
"Generic",
"{",
"s",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"s",... | // Lookup will retrieve a packet from the store. | [
"Lookup",
"will",
"retrieve",
"a",
"packet",
"from",
"the",
"store",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/session/packet_store.go#L50-L55 |
132,003 | 256dpi/gomqtt | session/packet_store.go | Delete | func (s *PacketStore) Delete(id packet.ID) {
s.mutex.Lock()
defer s.mutex.Unlock()
delete(s.packets, id)
} | go | func (s *PacketStore) Delete(id packet.ID) {
s.mutex.Lock()
defer s.mutex.Unlock()
delete(s.packets, id)
} | [
"func",
"(",
"s",
"*",
"PacketStore",
")",
"Delete",
"(",
"id",
"packet",
".",
"ID",
")",
"{",
"s",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"delete",
"(",
"s",
".",
"packets",
",",... | // Delete will remove a packet from the store. | [
"Delete",
"will",
"remove",
"a",
"packet",
"from",
"the",
"store",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/session/packet_store.go#L58-L63 |
132,004 | 256dpi/gomqtt | session/packet_store.go | All | func (s *PacketStore) All() []packet.Generic {
s.mutex.RLock()
defer s.mutex.RUnlock()
var all []packet.Generic
for _, pkt := range s.packets {
all = append(all, pkt)
}
return all
} | go | func (s *PacketStore) All() []packet.Generic {
s.mutex.RLock()
defer s.mutex.RUnlock()
var all []packet.Generic
for _, pkt := range s.packets {
all = append(all, pkt)
}
return all
} | [
"func",
"(",
"s",
"*",
"PacketStore",
")",
"All",
"(",
")",
"[",
"]",
"packet",
".",
"Generic",
"{",
"s",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n\n",
"var",
"all",
"[",
"]",
"packet"... | // All will return all packets currently saved in the store. | [
"All",
"will",
"return",
"all",
"packets",
"currently",
"saved",
"in",
"the",
"store",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/session/packet_store.go#L66-L77 |
132,005 | 256dpi/gomqtt | session/packet_store.go | Reset | func (s *PacketStore) Reset() {
s.mutex.Lock()
defer s.mutex.Unlock()
s.packets = make(map[packet.ID]packet.Generic)
} | go | func (s *PacketStore) Reset() {
s.mutex.Lock()
defer s.mutex.Unlock()
s.packets = make(map[packet.ID]packet.Generic)
} | [
"func",
"(",
"s",
"*",
"PacketStore",
")",
"Reset",
"(",
")",
"{",
"s",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"s",
".",
"packets",
"=",
"make",
"(",
"map",
"[",
"packet",
".",
... | // Reset will reset the store. | [
"Reset",
"will",
"reset",
"the",
"store",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/session/packet_store.go#L80-L85 |
132,006 | 256dpi/gomqtt | client/client.go | New | func New() *Client {
return &Client{
state: clientInitialized,
Session: session.NewMemorySession(),
futureStore: future.NewStore(),
}
} | go | func New() *Client {
return &Client{
state: clientInitialized,
Session: session.NewMemorySession(),
futureStore: future.NewStore(),
}
} | [
"func",
"New",
"(",
")",
"*",
"Client",
"{",
"return",
"&",
"Client",
"{",
"state",
":",
"clientInitialized",
",",
"Session",
":",
"session",
".",
"NewMemorySession",
"(",
")",
",",
"futureStore",
":",
"future",
".",
"NewStore",
"(",
")",
",",
"}",
"\n... | // New returns a new client that by default uses a fresh MemorySession. | [
"New",
"returns",
"a",
"new",
"client",
"that",
"by",
"default",
"uses",
"a",
"fresh",
"MemorySession",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/client.go#L135-L141 |
132,007 | 256dpi/gomqtt | client/client.go | Connect | func (c *Client) Connect(config *Config) (ConnectFuture, error) {
if config == nil {
panic("no config specified")
}
c.mutex.Lock()
defer c.mutex.Unlock()
// check if already connecting
if atomic.LoadUint32(&c.state) >= clientConnecting {
return nil, ErrClientAlreadyConnecting
}
// save config
c.config =... | go | func (c *Client) Connect(config *Config) (ConnectFuture, error) {
if config == nil {
panic("no config specified")
}
c.mutex.Lock()
defer c.mutex.Unlock()
// check if already connecting
if atomic.LoadUint32(&c.state) >= clientConnecting {
return nil, ErrClientAlreadyConnecting
}
// save config
c.config =... | [
"func",
"(",
"c",
"*",
"Client",
")",
"Connect",
"(",
"config",
"*",
"Config",
")",
"(",
"ConnectFuture",
",",
"error",
")",
"{",
"if",
"config",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"c",
".",
"mutex",
".",
"Lock",
... | // Connect opens the connection to the broker and sends a Connect packet. It will
// return a ConnectFuture that gets completed once a Connack has been
// received. If the Connect packet couldn't be transmitted it will return an error. | [
"Connect",
"opens",
"the",
"connection",
"to",
"the",
"broker",
"and",
"sends",
"a",
"Connect",
"packet",
".",
"It",
"will",
"return",
"a",
"ConnectFuture",
"that",
"gets",
"completed",
"once",
"a",
"Connack",
"has",
"been",
"received",
".",
"If",
"the",
"... | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/client.go#L146-L244 |
132,008 | 256dpi/gomqtt | client/client.go | PublishMessage | func (c *Client) PublishMessage(msg *packet.Message) (GenericFuture, error) {
c.mutex.Lock()
defer c.mutex.Unlock()
// check if connected
if atomic.LoadUint32(&c.state) != clientConnected {
return nil, ErrClientNotConnected
}
// allocate publish packet
publish := packet.NewPublish()
publish.Message = *msg
... | go | func (c *Client) PublishMessage(msg *packet.Message) (GenericFuture, error) {
c.mutex.Lock()
defer c.mutex.Unlock()
// check if connected
if atomic.LoadUint32(&c.state) != clientConnected {
return nil, ErrClientNotConnected
}
// allocate publish packet
publish := packet.NewPublish()
publish.Message = *msg
... | [
"func",
"(",
"c",
"*",
"Client",
")",
"PublishMessage",
"(",
"msg",
"*",
"packet",
".",
"Message",
")",
"(",
"GenericFuture",
",",
"error",
")",
"{",
"c",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mutex",
".",
"Unlock",
"(",
... | // PublishMessage will send a Publish containing the passed message. It will
// return a PublishFuture that gets completed once the quality of service flow
// has been completed. | [
"PublishMessage",
"will",
"send",
"a",
"Publish",
"containing",
"the",
"passed",
"message",
".",
"It",
"will",
"return",
"a",
"PublishFuture",
"that",
"gets",
"completed",
"once",
"the",
"quality",
"of",
"service",
"flow",
"has",
"been",
"completed",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/client.go#L263-L308 |
132,009 | 256dpi/gomqtt | client/client.go | Subscribe | func (c *Client) Subscribe(topic string, qos packet.QOS) (SubscribeFuture, error) {
return c.SubscribeMultiple([]packet.Subscription{
{Topic: topic, QOS: qos},
})
} | go | func (c *Client) Subscribe(topic string, qos packet.QOS) (SubscribeFuture, error) {
return c.SubscribeMultiple([]packet.Subscription{
{Topic: topic, QOS: qos},
})
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Subscribe",
"(",
"topic",
"string",
",",
"qos",
"packet",
".",
"QOS",
")",
"(",
"SubscribeFuture",
",",
"error",
")",
"{",
"return",
"c",
".",
"SubscribeMultiple",
"(",
"[",
"]",
"packet",
".",
"Subscription",
"{"... | // Subscribe will send a Subscribe packet containing one topic to subscribe. It
// will return a SubscribeFuture that gets completed once a Suback packet has
// been received. | [
"Subscribe",
"will",
"send",
"a",
"Subscribe",
"packet",
"containing",
"one",
"topic",
"to",
"subscribe",
".",
"It",
"will",
"return",
"a",
"SubscribeFuture",
"that",
"gets",
"completed",
"once",
"a",
"Suback",
"packet",
"has",
"been",
"received",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/client.go#L313-L317 |
132,010 | 256dpi/gomqtt | client/client.go | SubscribeMultiple | func (c *Client) SubscribeMultiple(subscriptions []packet.Subscription) (SubscribeFuture, error) {
c.mutex.Lock()
defer c.mutex.Unlock()
// check if connected
if atomic.LoadUint32(&c.state) != clientConnected {
return nil, ErrClientNotConnected
}
// allocate subscribe packet
subscribe := packet.NewSubscribe(... | go | func (c *Client) SubscribeMultiple(subscriptions []packet.Subscription) (SubscribeFuture, error) {
c.mutex.Lock()
defer c.mutex.Unlock()
// check if connected
if atomic.LoadUint32(&c.state) != clientConnected {
return nil, ErrClientNotConnected
}
// allocate subscribe packet
subscribe := packet.NewSubscribe(... | [
"func",
"(",
"c",
"*",
"Client",
")",
"SubscribeMultiple",
"(",
"subscriptions",
"[",
"]",
"packet",
".",
"Subscription",
")",
"(",
"SubscribeFuture",
",",
"error",
")",
"{",
"c",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mutex",
... | // SubscribeMultiple will send a Subscribe packet containing multiple topics to
// subscribe. It will return a SubscribeFuture that gets completed once a
// Suback packet has been received. | [
"SubscribeMultiple",
"will",
"send",
"a",
"Subscribe",
"packet",
"containing",
"multiple",
"topics",
"to",
"subscribe",
".",
"It",
"will",
"return",
"a",
"SubscribeFuture",
"that",
"gets",
"completed",
"once",
"a",
"Suback",
"packet",
"has",
"been",
"received",
... | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/client.go#L322-L352 |
132,011 | 256dpi/gomqtt | client/client.go | Unsubscribe | func (c *Client) Unsubscribe(topic string) (GenericFuture, error) {
return c.UnsubscribeMultiple([]string{topic})
} | go | func (c *Client) Unsubscribe(topic string) (GenericFuture, error) {
return c.UnsubscribeMultiple([]string{topic})
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Unsubscribe",
"(",
"topic",
"string",
")",
"(",
"GenericFuture",
",",
"error",
")",
"{",
"return",
"c",
".",
"UnsubscribeMultiple",
"(",
"[",
"]",
"string",
"{",
"topic",
"}",
")",
"\n",
"}"
] | // Unsubscribe will send a Unsubscribe packet containing one topic to unsubscribe.
// It will return a UnsubscribeFuture that gets completed once an Unsuback packet
// has been received. | [
"Unsubscribe",
"will",
"send",
"a",
"Unsubscribe",
"packet",
"containing",
"one",
"topic",
"to",
"unsubscribe",
".",
"It",
"will",
"return",
"a",
"UnsubscribeFuture",
"that",
"gets",
"completed",
"once",
"an",
"Unsuback",
"packet",
"has",
"been",
"received",
"."... | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/client.go#L357-L359 |
132,012 | 256dpi/gomqtt | client/client.go | UnsubscribeMultiple | func (c *Client) UnsubscribeMultiple(topics []string) (GenericFuture, error) {
c.mutex.Lock()
defer c.mutex.Unlock()
// check if connected
if atomic.LoadUint32(&c.state) != clientConnected {
return nil, ErrClientNotConnected
}
// allocate unsubscribe packet
unsubscribe := packet.NewUnsubscribe()
unsubscribe... | go | func (c *Client) UnsubscribeMultiple(topics []string) (GenericFuture, error) {
c.mutex.Lock()
defer c.mutex.Unlock()
// check if connected
if atomic.LoadUint32(&c.state) != clientConnected {
return nil, ErrClientNotConnected
}
// allocate unsubscribe packet
unsubscribe := packet.NewUnsubscribe()
unsubscribe... | [
"func",
"(",
"c",
"*",
"Client",
")",
"UnsubscribeMultiple",
"(",
"topics",
"[",
"]",
"string",
")",
"(",
"GenericFuture",
",",
"error",
")",
"{",
"c",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mutex",
".",
"Unlock",
"(",
")",
... | // UnsubscribeMultiple will send a Unsubscribe packet containing multiple
// topics to unsubscribe. It will return a UnsubscribeFuture that gets completed
// once an Unsuback packet has been received. | [
"UnsubscribeMultiple",
"will",
"send",
"a",
"Unsubscribe",
"packet",
"containing",
"multiple",
"topics",
"to",
"unsubscribe",
".",
"It",
"will",
"return",
"a",
"UnsubscribeFuture",
"that",
"gets",
"completed",
"once",
"an",
"Unsuback",
"packet",
"has",
"been",
"re... | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/client.go#L364-L391 |
132,013 | 256dpi/gomqtt | client/client.go | Disconnect | func (c *Client) Disconnect(timeout ...time.Duration) error {
c.mutex.Lock()
defer c.mutex.Unlock()
// check if connected
if atomic.LoadUint32(&c.state) != clientConnected {
return ErrClientNotConnected
}
// finish current packets
if len(timeout) > 0 {
c.futureStore.Await(timeout[0])
}
// set state
ato... | go | func (c *Client) Disconnect(timeout ...time.Duration) error {
c.mutex.Lock()
defer c.mutex.Unlock()
// check if connected
if atomic.LoadUint32(&c.state) != clientConnected {
return ErrClientNotConnected
}
// finish current packets
if len(timeout) > 0 {
c.futureStore.Await(timeout[0])
}
// set state
ato... | [
"func",
"(",
"c",
"*",
"Client",
")",
"Disconnect",
"(",
"timeout",
"...",
"time",
".",
"Duration",
")",
"error",
"{",
"c",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// check if connected... | // Disconnect will send a Disconnect packet and close the connection.
//
// If a timeout is specified, the client will wait the specified amount of time
// for all queued futures to complete or cancel. If no timeout is specified it
// will not wait at all. | [
"Disconnect",
"will",
"send",
"a",
"Disconnect",
"packet",
"and",
"close",
"the",
"connection",
".",
"If",
"a",
"timeout",
"is",
"specified",
"the",
"client",
"will",
"wait",
"the",
"specified",
"amount",
"of",
"time",
"for",
"all",
"queued",
"futures",
"to"... | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/client.go#L398-L419 |
132,014 | 256dpi/gomqtt | client/client.go | Close | func (c *Client) Close() error {
c.mutex.Lock()
defer c.mutex.Unlock()
// check if connected
if atomic.LoadUint32(&c.state) < clientConnecting {
return ErrClientNotConnected
}
return c.end(nil, false)
} | go | func (c *Client) Close() error {
c.mutex.Lock()
defer c.mutex.Unlock()
// check if connected
if atomic.LoadUint32(&c.state) < clientConnecting {
return ErrClientNotConnected
}
return c.end(nil, false)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Close",
"(",
")",
"error",
"{",
"c",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// check if connected",
"if",
"atomic",
".",
"LoadUint32",
"(",
"&"... | // Close closes the client immediately without sending a Disconnect packet and
// waiting for outgoing transmissions to finish. | [
"Close",
"closes",
"the",
"client",
"immediately",
"without",
"sending",
"a",
"Disconnect",
"packet",
"and",
"waiting",
"for",
"outgoing",
"transmissions",
"to",
"finish",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/client.go#L423-L433 |
132,015 | 256dpi/gomqtt | client/client.go | processConnack | func (c *Client) processConnack(connack *packet.Connack) error {
// check state
if atomic.LoadUint32(&c.state) != clientConnecting {
return nil // ignore wrongly sent Connack packet
}
// set state
atomic.StoreUint32(&c.state, clientConnacked)
// fill future
c.connectFuture.Data.Store(sessionPresentKey, conna... | go | func (c *Client) processConnack(connack *packet.Connack) error {
// check state
if atomic.LoadUint32(&c.state) != clientConnecting {
return nil // ignore wrongly sent Connack packet
}
// set state
atomic.StoreUint32(&c.state, clientConnacked)
// fill future
c.connectFuture.Data.Store(sessionPresentKey, conna... | [
"func",
"(",
"c",
"*",
"Client",
")",
"processConnack",
"(",
"connack",
"*",
"packet",
".",
"Connack",
")",
"error",
"{",
"// check state",
"if",
"atomic",
".",
"LoadUint32",
"(",
"&",
"c",
".",
"state",
")",
"!=",
"clientConnecting",
"{",
"return",
"nil... | // handle the incoming Connack packet | [
"handle",
"the",
"incoming",
"Connack",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/client.go#L507-L556 |
132,016 | 256dpi/gomqtt | client/client.go | processSuback | func (c *Client) processSuback(suback *packet.Suback) error {
// remove packet from store
err := c.Session.DeletePacket(session.Outgoing, suback.ID)
if err != nil {
return err
}
// get future
subscribeFuture := c.futureStore.Get(suback.ID)
if subscribeFuture == nil {
return nil // ignore a wrongly sent Suba... | go | func (c *Client) processSuback(suback *packet.Suback) error {
// remove packet from store
err := c.Session.DeletePacket(session.Outgoing, suback.ID)
if err != nil {
return err
}
// get future
subscribeFuture := c.futureStore.Get(suback.ID)
if subscribeFuture == nil {
return nil // ignore a wrongly sent Suba... | [
"func",
"(",
"c",
"*",
"Client",
")",
"processSuback",
"(",
"suback",
"*",
"packet",
".",
"Suback",
")",
"error",
"{",
"// remove packet from store",
"err",
":=",
"c",
".",
"Session",
".",
"DeletePacket",
"(",
"session",
".",
"Outgoing",
",",
"suback",
"."... | // handle an incoming Suback packet | [
"handle",
"an",
"incoming",
"Suback",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/client.go#L559-L590 |
132,017 | 256dpi/gomqtt | client/client.go | processUnsuback | func (c *Client) processUnsuback(unsuback *packet.Unsuback) error {
// remove packet from store
err := c.Session.DeletePacket(session.Outgoing, unsuback.ID)
if err != nil {
return err
}
// get future
unsubscribeFuture := c.futureStore.Get(unsuback.ID)
if unsubscribeFuture == nil {
return nil // ignore a wro... | go | func (c *Client) processUnsuback(unsuback *packet.Unsuback) error {
// remove packet from store
err := c.Session.DeletePacket(session.Outgoing, unsuback.ID)
if err != nil {
return err
}
// get future
unsubscribeFuture := c.futureStore.Get(unsuback.ID)
if unsubscribeFuture == nil {
return nil // ignore a wro... | [
"func",
"(",
"c",
"*",
"Client",
")",
"processUnsuback",
"(",
"unsuback",
"*",
"packet",
".",
"Unsuback",
")",
"error",
"{",
"// remove packet from store",
"err",
":=",
"c",
".",
"Session",
".",
"DeletePacket",
"(",
"session",
".",
"Outgoing",
",",
"unsuback... | // handle an incoming Unsuback packet | [
"handle",
"an",
"incoming",
"Unsuback",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/client.go#L593-L613 |
132,018 | 256dpi/gomqtt | client/client.go | processPublish | func (c *Client) processPublish(publish *packet.Publish) error {
// call callback for unacknowledged and directly acknowledged messages
if publish.Message.QOS <= 1 {
if c.Callback != nil {
err := c.Callback(&publish.Message, nil)
if err != nil {
return c.die(err, true, true)
}
}
}
// handle qos 1 ... | go | func (c *Client) processPublish(publish *packet.Publish) error {
// call callback for unacknowledged and directly acknowledged messages
if publish.Message.QOS <= 1 {
if c.Callback != nil {
err := c.Callback(&publish.Message, nil)
if err != nil {
return c.die(err, true, true)
}
}
}
// handle qos 1 ... | [
"func",
"(",
"c",
"*",
"Client",
")",
"processPublish",
"(",
"publish",
"*",
"packet",
".",
"Publish",
")",
"error",
"{",
"// call callback for unacknowledged and directly acknowledged messages",
"if",
"publish",
".",
"Message",
".",
"QOS",
"<=",
"1",
"{",
"if",
... | // handle an incoming Publish packet | [
"handle",
"an",
"incoming",
"Publish",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/client.go#L616-L660 |
132,019 | 256dpi/gomqtt | client/client.go | processPubackAndPubcomp | func (c *Client) processPubackAndPubcomp(id packet.ID) error {
// remove packet from store
err := c.Session.DeletePacket(session.Outgoing, id)
if err != nil {
return err
}
// get future
publishFuture := c.futureStore.Get(id)
if publishFuture == nil {
return nil // ignore a wrongly sent Puback or Pubcomp pac... | go | func (c *Client) processPubackAndPubcomp(id packet.ID) error {
// remove packet from store
err := c.Session.DeletePacket(session.Outgoing, id)
if err != nil {
return err
}
// get future
publishFuture := c.futureStore.Get(id)
if publishFuture == nil {
return nil // ignore a wrongly sent Puback or Pubcomp pac... | [
"func",
"(",
"c",
"*",
"Client",
")",
"processPubackAndPubcomp",
"(",
"id",
"packet",
".",
"ID",
")",
"error",
"{",
"// remove packet from store",
"err",
":=",
"c",
".",
"Session",
".",
"DeletePacket",
"(",
"session",
".",
"Outgoing",
",",
"id",
")",
"\n",... | // handle an incoming Puback or Pubcomp packet | [
"handle",
"an",
"incoming",
"Puback",
"or",
"Pubcomp",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/client.go#L663-L683 |
132,020 | 256dpi/gomqtt | client/client.go | processPubrec | func (c *Client) processPubrec(id packet.ID) error {
// prepare pubrel packet
pubrel := packet.NewPubrel()
pubrel.ID = id
// overwrite stored Publish with the Pubrel packet
err := c.Session.SavePacket(session.Outgoing, pubrel)
if err != nil {
return c.die(err, true, false)
}
// send packet
err = c.send(pub... | go | func (c *Client) processPubrec(id packet.ID) error {
// prepare pubrel packet
pubrel := packet.NewPubrel()
pubrel.ID = id
// overwrite stored Publish with the Pubrel packet
err := c.Session.SavePacket(session.Outgoing, pubrel)
if err != nil {
return c.die(err, true, false)
}
// send packet
err = c.send(pub... | [
"func",
"(",
"c",
"*",
"Client",
")",
"processPubrec",
"(",
"id",
"packet",
".",
"ID",
")",
"error",
"{",
"// prepare pubrel packet",
"pubrel",
":=",
"packet",
".",
"NewPubrel",
"(",
")",
"\n",
"pubrel",
".",
"ID",
"=",
"id",
"\n\n",
"// overwrite stored P... | // handle an incoming Pubrec packet | [
"handle",
"an",
"incoming",
"Pubrec",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/client.go#L686-L704 |
132,021 | 256dpi/gomqtt | client/client.go | processPubrel | func (c *Client) processPubrel(id packet.ID) error {
// get packet from store
pkt, err := c.Session.LookupPacket(session.Incoming, id)
if err != nil {
return c.die(err, true, false)
}
// get packet from store
publish, ok := pkt.(*packet.Publish)
if !ok {
return nil // ignore a wrongly sent Pubrel packet
}
... | go | func (c *Client) processPubrel(id packet.ID) error {
// get packet from store
pkt, err := c.Session.LookupPacket(session.Incoming, id)
if err != nil {
return c.die(err, true, false)
}
// get packet from store
publish, ok := pkt.(*packet.Publish)
if !ok {
return nil // ignore a wrongly sent Pubrel packet
}
... | [
"func",
"(",
"c",
"*",
"Client",
")",
"processPubrel",
"(",
"id",
"packet",
".",
"ID",
")",
"error",
"{",
"// get packet from store",
"pkt",
",",
"err",
":=",
"c",
".",
"Session",
".",
"LookupPacket",
"(",
"session",
".",
"Incoming",
",",
"id",
")",
"\... | // handle an incoming Pubrel packet | [
"handle",
"an",
"incoming",
"Pubrel",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/client.go#L707-L745 |
132,022 | 256dpi/gomqtt | client/client.go | die | func (c *Client) die(err error, close bool, fromCallback bool) error {
c.finish.Do(func() {
err = c.cleanup(err, close, false)
if c.Callback != nil && !fromCallback {
returnedErr := c.Callback(nil, err)
if returnedErr == nil {
err = nil
}
}
})
return err
} | go | func (c *Client) die(err error, close bool, fromCallback bool) error {
c.finish.Do(func() {
err = c.cleanup(err, close, false)
if c.Callback != nil && !fromCallback {
returnedErr := c.Callback(nil, err)
if returnedErr == nil {
err = nil
}
}
})
return err
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"die",
"(",
"err",
"error",
",",
"close",
"bool",
",",
"fromCallback",
"bool",
")",
"error",
"{",
"c",
".",
"finish",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"err",
"=",
"c",
".",
"cleanup",
"(",
"err",
",",... | // used for closing and cleaning up from internal goroutines | [
"used",
"for",
"closing",
"and",
"cleaning",
"up",
"from",
"internal",
"goroutines"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/client.go#L840-L853 |
132,023 | 256dpi/gomqtt | client/client.go | end | func (c *Client) end(err error, possiblyClosed bool) error {
// close connection
err = c.cleanup(err, true, true)
// shutdown goroutines
c.tomb.Kill(nil)
// wait for all goroutines to exit
// goroutines will send eventual errors through the callback
c.tomb.Wait()
// do cleanup
return err
} | go | func (c *Client) end(err error, possiblyClosed bool) error {
// close connection
err = c.cleanup(err, true, true)
// shutdown goroutines
c.tomb.Kill(nil)
// wait for all goroutines to exit
// goroutines will send eventual errors through the callback
c.tomb.Wait()
// do cleanup
return err
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"end",
"(",
"err",
"error",
",",
"possiblyClosed",
"bool",
")",
"error",
"{",
"// close connection",
"err",
"=",
"c",
".",
"cleanup",
"(",
"err",
",",
"true",
",",
"true",
")",
"\n\n",
"// shutdown goroutines",
"c",
... | // called by Disconnect and Close | [
"called",
"by",
"Disconnect",
"and",
"Close"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/client.go#L856-L869 |
132,024 | 256dpi/gomqtt | broker/backend.go | NewMemoryBackend | func NewMemoryBackend() *MemoryBackend {
return &MemoryBackend{
SessionQueueSize: 100,
KillTimeout: 5 * time.Second,
activeClients: make(map[string]*Client),
storedSessions: make(map[string]*memorySession),
temporarySessions: make(map[*Client]*memorySession),
retainedMessages: topic.NewTree(... | go | func NewMemoryBackend() *MemoryBackend {
return &MemoryBackend{
SessionQueueSize: 100,
KillTimeout: 5 * time.Second,
activeClients: make(map[string]*Client),
storedSessions: make(map[string]*memorySession),
temporarySessions: make(map[*Client]*memorySession),
retainedMessages: topic.NewTree(... | [
"func",
"NewMemoryBackend",
"(",
")",
"*",
"MemoryBackend",
"{",
"return",
"&",
"MemoryBackend",
"{",
"SessionQueueSize",
":",
"100",
",",
"KillTimeout",
":",
"5",
"*",
"time",
".",
"Second",
",",
"activeClients",
":",
"make",
"(",
"map",
"[",
"string",
"]... | // NewMemoryBackend returns a new MemoryBackend. | [
"NewMemoryBackend",
"returns",
"a",
"new",
"MemoryBackend",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/backend.go#L109-L118 |
132,025 | 256dpi/gomqtt | broker/backend.go | Authenticate | func (m *MemoryBackend) Authenticate(client *Client, user, password string) (bool, error) {
// acquire global mutex
m.globalMutex.Lock()
defer m.globalMutex.Unlock()
// return error if closing
if m.closing {
return false, ErrClosing
}
// allow all if there are no credentials
if m.Credentials == nil {
retu... | go | func (m *MemoryBackend) Authenticate(client *Client, user, password string) (bool, error) {
// acquire global mutex
m.globalMutex.Lock()
defer m.globalMutex.Unlock()
// return error if closing
if m.closing {
return false, ErrClosing
}
// allow all if there are no credentials
if m.Credentials == nil {
retu... | [
"func",
"(",
"m",
"*",
"MemoryBackend",
")",
"Authenticate",
"(",
"client",
"*",
"Client",
",",
"user",
",",
"password",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"// acquire global mutex",
"m",
".",
"globalMutex",
".",
"Lock",
"(",
")",
"\n",
... | // Authenticate will authenticates a clients credentials. | [
"Authenticate",
"will",
"authenticates",
"a",
"clients",
"credentials",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/backend.go#L121-L142 |
132,026 | 256dpi/gomqtt | broker/backend.go | Setup | func (m *MemoryBackend) Setup(client *Client, id string, clean bool) (Session, bool, error) {
// acquire setup mutex
m.setupMutex.Lock()
defer m.setupMutex.Unlock()
// acquire global mutex
m.globalMutex.Lock()
defer m.globalMutex.Unlock()
// return error if closing
if m.closing {
return nil, false, ErrClosi... | go | func (m *MemoryBackend) Setup(client *Client, id string, clean bool) (Session, bool, error) {
// acquire setup mutex
m.setupMutex.Lock()
defer m.setupMutex.Unlock()
// acquire global mutex
m.globalMutex.Lock()
defer m.globalMutex.Unlock()
// return error if closing
if m.closing {
return nil, false, ErrClosi... | [
"func",
"(",
"m",
"*",
"MemoryBackend",
")",
"Setup",
"(",
"client",
"*",
"Client",
",",
"id",
"string",
",",
"clean",
"bool",
")",
"(",
"Session",
",",
"bool",
",",
"error",
")",
"{",
"// acquire setup mutex",
"m",
".",
"setupMutex",
".",
"Lock",
"(",... | // Setup will close existing clients and return an appropriate session. | [
"Setup",
"will",
"close",
"existing",
"clients",
"and",
"return",
"an",
"appropriate",
"session",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/backend.go#L145-L258 |
132,027 | 256dpi/gomqtt | broker/backend.go | Subscribe | func (m *MemoryBackend) Subscribe(client *Client, subs []packet.Subscription, ack Ack) error {
// acquire global mutex
m.globalMutex.Lock()
defer m.globalMutex.Unlock()
// save subscription
for _, sub := range subs {
client.Session().(*memorySession).subscriptions.Set(sub.Topic, sub)
}
// call ack if provide... | go | func (m *MemoryBackend) Subscribe(client *Client, subs []packet.Subscription, ack Ack) error {
// acquire global mutex
m.globalMutex.Lock()
defer m.globalMutex.Unlock()
// save subscription
for _, sub := range subs {
client.Session().(*memorySession).subscriptions.Set(sub.Topic, sub)
}
// call ack if provide... | [
"func",
"(",
"m",
"*",
"MemoryBackend",
")",
"Subscribe",
"(",
"client",
"*",
"Client",
",",
"subs",
"[",
"]",
"packet",
".",
"Subscription",
",",
"ack",
"Ack",
")",
"error",
"{",
"// acquire global mutex",
"m",
".",
"globalMutex",
".",
"Lock",
"(",
")",... | // Subscribe will store the subscription and queue retained messages. | [
"Subscribe",
"will",
"store",
"the",
"subscription",
"and",
"queue",
"retained",
"messages",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/backend.go#L266-L301 |
132,028 | 256dpi/gomqtt | broker/backend.go | Unsubscribe | func (m *MemoryBackend) Unsubscribe(client *Client, topics []string, ack Ack) error {
// delete subscriptions
for _, t := range topics {
client.Session().(*memorySession).subscriptions.Empty(t)
}
// call ack if provided
if ack != nil {
ack()
}
return nil
} | go | func (m *MemoryBackend) Unsubscribe(client *Client, topics []string, ack Ack) error {
// delete subscriptions
for _, t := range topics {
client.Session().(*memorySession).subscriptions.Empty(t)
}
// call ack if provided
if ack != nil {
ack()
}
return nil
} | [
"func",
"(",
"m",
"*",
"MemoryBackend",
")",
"Unsubscribe",
"(",
"client",
"*",
"Client",
",",
"topics",
"[",
"]",
"string",
",",
"ack",
"Ack",
")",
"error",
"{",
"// delete subscriptions",
"for",
"_",
",",
"t",
":=",
"range",
"topics",
"{",
"client",
... | // Unsubscribe will delete the subscription. | [
"Unsubscribe",
"will",
"delete",
"the",
"subscription",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/backend.go#L304-L316 |
132,029 | 256dpi/gomqtt | broker/backend.go | Publish | func (m *MemoryBackend) Publish(client *Client, msg *packet.Message, ack Ack) error {
// acquire global mutex
m.globalMutex.Lock()
defer m.globalMutex.Unlock()
// this implementation is very basic and will block the backend on every
// publish. clients that stay connected but won't drain their queue will
// even... | go | func (m *MemoryBackend) Publish(client *Client, msg *packet.Message, ack Ack) error {
// acquire global mutex
m.globalMutex.Lock()
defer m.globalMutex.Unlock()
// this implementation is very basic and will block the backend on every
// publish. clients that stay connected but won't drain their queue will
// even... | [
"func",
"(",
"m",
"*",
"MemoryBackend",
")",
"Publish",
"(",
"client",
"*",
"Client",
",",
"msg",
"*",
"packet",
".",
"Message",
",",
"ack",
"Ack",
")",
"error",
"{",
"// acquire global mutex",
"m",
".",
"globalMutex",
".",
"Lock",
"(",
")",
"\n",
"def... | // Publish will handle retained messages and add the message to the session queues. | [
"Publish",
"will",
"handle",
"retained",
"messages",
"and",
"add",
"the",
"message",
"to",
"the",
"session",
"queues",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/backend.go#L319-L408 |
132,030 | 256dpi/gomqtt | broker/backend.go | Dequeue | func (m *MemoryBackend) Dequeue(client *Client) (*packet.Message, Ack, error) {
// mutex locking not needed
// get session
sess := client.Session().(*memorySession)
// this implementation is very basic and will dequeue messages immediately
// and not return no ack. messages are lost if the client fails to handle... | go | func (m *MemoryBackend) Dequeue(client *Client) (*packet.Message, Ack, error) {
// mutex locking not needed
// get session
sess := client.Session().(*memorySession)
// this implementation is very basic and will dequeue messages immediately
// and not return no ack. messages are lost if the client fails to handle... | [
"func",
"(",
"m",
"*",
"MemoryBackend",
")",
"Dequeue",
"(",
"client",
"*",
"Client",
")",
"(",
"*",
"packet",
".",
"Message",
",",
"Ack",
",",
"error",
")",
"{",
"// mutex locking not needed",
"// get session",
"sess",
":=",
"client",
".",
"Session",
"(",... | // Dequeue will get the next message from the temporary or stored queue. | [
"Dequeue",
"will",
"get",
"the",
"next",
"message",
"from",
"the",
"temporary",
"or",
"stored",
"queue",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/backend.go#L411-L429 |
132,031 | 256dpi/gomqtt | broker/backend.go | Terminate | func (m *MemoryBackend) Terminate(client *Client) error {
// acquire global mutex
m.globalMutex.Lock()
defer m.globalMutex.Unlock()
// release session if available
sess, ok := client.Session().(*memorySession)
if ok && sess != nil {
sess.owner = nil
}
// remove any temporary session
delete(m.temporarySessi... | go | func (m *MemoryBackend) Terminate(client *Client) error {
// acquire global mutex
m.globalMutex.Lock()
defer m.globalMutex.Unlock()
// release session if available
sess, ok := client.Session().(*memorySession)
if ok && sess != nil {
sess.owner = nil
}
// remove any temporary session
delete(m.temporarySessi... | [
"func",
"(",
"m",
"*",
"MemoryBackend",
")",
"Terminate",
"(",
"client",
"*",
"Client",
")",
"error",
"{",
"// acquire global mutex",
"m",
".",
"globalMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"globalMutex",
".",
"Unlock",
"(",
")",
"\n\n",... | // Terminate will disassociate the session from the client. | [
"Terminate",
"will",
"disassociate",
"the",
"session",
"from",
"the",
"client",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/backend.go#L432-L450 |
132,032 | 256dpi/gomqtt | broker/backend.go | Log | func (m *MemoryBackend) Log(event LogEvent, client *Client, pkt packet.Generic, msg *packet.Message, err error) {
// call logger if available
if m.Logger != nil {
m.Logger(event, client, pkt, msg, err)
}
} | go | func (m *MemoryBackend) Log(event LogEvent, client *Client, pkt packet.Generic, msg *packet.Message, err error) {
// call logger if available
if m.Logger != nil {
m.Logger(event, client, pkt, msg, err)
}
} | [
"func",
"(",
"m",
"*",
"MemoryBackend",
")",
"Log",
"(",
"event",
"LogEvent",
",",
"client",
"*",
"Client",
",",
"pkt",
"packet",
".",
"Generic",
",",
"msg",
"*",
"packet",
".",
"Message",
",",
"err",
"error",
")",
"{",
"// call logger if available",
"if... | // Log will call the associated logger. | [
"Log",
"will",
"call",
"the",
"associated",
"logger",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/backend.go#L453-L458 |
132,033 | 256dpi/gomqtt | broker/backend.go | Close | func (m *MemoryBackend) Close(timeout time.Duration) bool {
// acquire global mutex
m.globalMutex.Lock()
// set closing
m.closing = true
// prepare list
var clients []*Client
// close temporary sessions
for _, sess := range m.temporarySessions {
sess.owner.Close()
clients = append(clients, sess.owner)
}... | go | func (m *MemoryBackend) Close(timeout time.Duration) bool {
// acquire global mutex
m.globalMutex.Lock()
// set closing
m.closing = true
// prepare list
var clients []*Client
// close temporary sessions
for _, sess := range m.temporarySessions {
sess.owner.Close()
clients = append(clients, sess.owner)
}... | [
"func",
"(",
"m",
"*",
"MemoryBackend",
")",
"Close",
"(",
"timeout",
"time",
".",
"Duration",
")",
"bool",
"{",
"// acquire global mutex",
"m",
".",
"globalMutex",
".",
"Lock",
"(",
")",
"\n\n",
"// set closing",
"m",
".",
"closing",
"=",
"true",
"\n\n",
... | // Close will close all active clients and close the backend. The return value
// denotes if the timeout has been reached. | [
"Close",
"will",
"close",
"all",
"active",
"clients",
"and",
"close",
"the",
"backend",
".",
"The",
"return",
"value",
"denotes",
"if",
"the",
"timeout",
"has",
"been",
"reached",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/backend.go#L462-L508 |
132,034 | 256dpi/gomqtt | client/config.go | NewConfig | func NewConfig(url string) *Config {
return &Config{
BrokerURL: url,
CleanSession: true,
KeepAlive: "30s",
ValidateSubs: true,
}
} | go | func NewConfig(url string) *Config {
return &Config{
BrokerURL: url,
CleanSession: true,
KeepAlive: "30s",
ValidateSubs: true,
}
} | [
"func",
"NewConfig",
"(",
"url",
"string",
")",
"*",
"Config",
"{",
"return",
"&",
"Config",
"{",
"BrokerURL",
":",
"url",
",",
"CleanSession",
":",
"true",
",",
"KeepAlive",
":",
"\"",
"\"",
",",
"ValidateSubs",
":",
"true",
",",
"}",
"\n",
"}"
] | // NewConfig creates a new Config using the specified URL. | [
"NewConfig",
"creates",
"a",
"new",
"Config",
"using",
"the",
"specified",
"URL",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/config.go#L44-L51 |
132,035 | 256dpi/gomqtt | client/config.go | NewConfigWithClientID | func NewConfigWithClientID(url, id string) *Config {
config := NewConfig(url)
config.ClientID = id
return config
} | go | func NewConfigWithClientID(url, id string) *Config {
config := NewConfig(url)
config.ClientID = id
return config
} | [
"func",
"NewConfigWithClientID",
"(",
"url",
",",
"id",
"string",
")",
"*",
"Config",
"{",
"config",
":=",
"NewConfig",
"(",
"url",
")",
"\n",
"config",
".",
"ClientID",
"=",
"id",
"\n",
"return",
"config",
"\n",
"}"
] | // NewConfigWithClientID creates a new Config using the specified URL and client ID. | [
"NewConfigWithClientID",
"creates",
"a",
"new",
"Config",
"using",
"the",
"specified",
"URL",
"and",
"client",
"ID",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/config.go#L54-L58 |
132,036 | 256dpi/gomqtt | transport/dialer.go | NewDialer | func NewDialer() *Dialer {
return &Dialer{
DefaultTCPPort: "1883",
DefaultTLSPort: "8883",
DefaultWSPort: "80",
DefaultWSSPort: "443",
webSocketDialer: &websocket.Dialer{
Proxy: http.ProxyFromEnvironment,
Subprotocols: []string{"mqtt"},
},
}
} | go | func NewDialer() *Dialer {
return &Dialer{
DefaultTCPPort: "1883",
DefaultTLSPort: "8883",
DefaultWSPort: "80",
DefaultWSSPort: "443",
webSocketDialer: &websocket.Dialer{
Proxy: http.ProxyFromEnvironment,
Subprotocols: []string{"mqtt"},
},
}
} | [
"func",
"NewDialer",
"(",
")",
"*",
"Dialer",
"{",
"return",
"&",
"Dialer",
"{",
"DefaultTCPPort",
":",
"\"",
"\"",
",",
"DefaultTLSPort",
":",
"\"",
"\"",
",",
"DefaultWSPort",
":",
"\"",
"\"",
",",
"DefaultWSSPort",
":",
"\"",
"\"",
",",
"webSocketDial... | // NewDialer returns a new Dialer. | [
"NewDialer",
"returns",
"a",
"new",
"Dialer",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/transport/dialer.go#L29-L40 |
132,037 | 256dpi/gomqtt | transport/dialer.go | Dial | func (d *Dialer) Dial(urlString string) (Conn, error) {
// ensure write delay default
if d.MaxWriteDelay == 0 {
d.MaxWriteDelay = 10 * time.Millisecond
}
urlParts, err := url.ParseRequestURI(urlString)
if err != nil {
return nil, err
}
host, port, err := net.SplitHostPort(urlParts.Host)
if err != nil {
... | go | func (d *Dialer) Dial(urlString string) (Conn, error) {
// ensure write delay default
if d.MaxWriteDelay == 0 {
d.MaxWriteDelay = 10 * time.Millisecond
}
urlParts, err := url.ParseRequestURI(urlString)
if err != nil {
return nil, err
}
host, port, err := net.SplitHostPort(urlParts.Host)
if err != nil {
... | [
"func",
"(",
"d",
"*",
"Dialer",
")",
"Dial",
"(",
"urlString",
"string",
")",
"(",
"Conn",
",",
"error",
")",
"{",
"// ensure write delay default",
"if",
"d",
".",
"MaxWriteDelay",
"==",
"0",
"{",
"d",
".",
"MaxWriteDelay",
"=",
"10",
"*",
"time",
"."... | // Dial initiates a connection based in information extracted from an URL. | [
"Dial",
"initiates",
"a",
"connection",
"based",
"in",
"information",
"extracted",
"from",
"an",
"URL",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/transport/dialer.go#L54-L124 |
132,038 | 256dpi/gomqtt | packet/identified.go | identifiedDecode | func identifiedDecode(src []byte, t Type) (int, ID, error) {
total := 0
// decode header
hl, _, rl, err := headerDecode(src, t)
total += hl
if err != nil {
return total, 0, err
}
// check remaining length
if rl != 2 {
return total, 0, makeError(t, "expected remaining length to be 2")
}
// read packet i... | go | func identifiedDecode(src []byte, t Type) (int, ID, error) {
total := 0
// decode header
hl, _, rl, err := headerDecode(src, t)
total += hl
if err != nil {
return total, 0, err
}
// check remaining length
if rl != 2 {
return total, 0, makeError(t, "expected remaining length to be 2")
}
// read packet i... | [
"func",
"identifiedDecode",
"(",
"src",
"[",
"]",
"byte",
",",
"t",
"Type",
")",
"(",
"int",
",",
"ID",
",",
"error",
")",
"{",
"total",
":=",
"0",
"\n\n",
"// decode header",
"hl",
",",
"_",
",",
"rl",
",",
"err",
":=",
"headerDecode",
"(",
"src",... | // decodes an identified packet | [
"decodes",
"an",
"identified",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/packet/identified.go#L14-L39 |
132,039 | 256dpi/gomqtt | packet/identified.go | identifiedEncode | func identifiedEncode(dst []byte, id ID, t Type) (int, error) {
total := 0
// check packet id
if !id.Valid() {
return total, makeError(t, "packet id must be grater than zero")
}
// encode header
n, err := headerEncode(dst[total:], 0, 2, identifiedLen(), t)
total += n
if err != nil {
return total, err
}
... | go | func identifiedEncode(dst []byte, id ID, t Type) (int, error) {
total := 0
// check packet id
if !id.Valid() {
return total, makeError(t, "packet id must be grater than zero")
}
// encode header
n, err := headerEncode(dst[total:], 0, 2, identifiedLen(), t)
total += n
if err != nil {
return total, err
}
... | [
"func",
"identifiedEncode",
"(",
"dst",
"[",
"]",
"byte",
",",
"id",
"ID",
",",
"t",
"Type",
")",
"(",
"int",
",",
"error",
")",
"{",
"total",
":=",
"0",
"\n\n",
"// check packet id",
"if",
"!",
"id",
".",
"Valid",
"(",
")",
"{",
"return",
"total",... | // encodes an identified packet | [
"encodes",
"an",
"identified",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/packet/identified.go#L42-L62 |
132,040 | 256dpi/gomqtt | broker/engine.go | NewEngine | func NewEngine(backend Backend) *Engine {
return &Engine{
Backend: backend,
ConnectTimeout: 10 * time.Second,
}
} | go | func NewEngine(backend Backend) *Engine {
return &Engine{
Backend: backend,
ConnectTimeout: 10 * time.Second,
}
} | [
"func",
"NewEngine",
"(",
"backend",
"Backend",
")",
"*",
"Engine",
"{",
"return",
"&",
"Engine",
"{",
"Backend",
":",
"backend",
",",
"ConnectTimeout",
":",
"10",
"*",
"time",
".",
"Second",
",",
"}",
"\n",
"}"
] | // NewEngine returns a new Engine. | [
"NewEngine",
"returns",
"a",
"new",
"Engine",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/engine.go#L34-L39 |
132,041 | 256dpi/gomqtt | broker/engine.go | Accept | func (e *Engine) Accept(server transport.Server) {
e.tomb.Go(func() error {
for {
// return if dying
if !e.tomb.Alive() {
return tomb.ErrDying
}
// accept next connection
conn, err := server.Accept()
if err != nil {
// call error callback if available
if e.OnError != nil {
e.OnErr... | go | func (e *Engine) Accept(server transport.Server) {
e.tomb.Go(func() error {
for {
// return if dying
if !e.tomb.Alive() {
return tomb.ErrDying
}
// accept next connection
conn, err := server.Accept()
if err != nil {
// call error callback if available
if e.OnError != nil {
e.OnErr... | [
"func",
"(",
"e",
"*",
"Engine",
")",
"Accept",
"(",
"server",
"transport",
".",
"Server",
")",
"{",
"e",
".",
"tomb",
".",
"Go",
"(",
"func",
"(",
")",
"error",
"{",
"for",
"{",
"// return if dying",
"if",
"!",
"e",
".",
"tomb",
".",
"Alive",
"(... | // Accept begins accepting connections from the passed server. | [
"Accept",
"begins",
"accepting",
"connections",
"from",
"the",
"passed",
"server",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/engine.go#L42-L67 |
132,042 | 256dpi/gomqtt | broker/engine.go | Handle | func (e *Engine) Handle(conn transport.Conn) bool {
// check conn
if conn == nil {
panic("passed conn is nil")
}
// acquire mutex
e.mutex.Lock()
defer e.mutex.Unlock()
// close conn immediately when dying
if !e.tomb.Alive() {
_ = conn.Close()
return false
}
// set default read limit
conn.SetReadLimi... | go | func (e *Engine) Handle(conn transport.Conn) bool {
// check conn
if conn == nil {
panic("passed conn is nil")
}
// acquire mutex
e.mutex.Lock()
defer e.mutex.Unlock()
// close conn immediately when dying
if !e.tomb.Alive() {
_ = conn.Close()
return false
}
// set default read limit
conn.SetReadLimi... | [
"func",
"(",
"e",
"*",
"Engine",
")",
"Handle",
"(",
"conn",
"transport",
".",
"Conn",
")",
"bool",
"{",
"// check conn",
"if",
"conn",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// acquire mutex",
"e",
".",
"mutex",
".",
... | // Handle takes over responsibility and handles a transport.Conn. It returns
// false if the engine is closing and the connection has been closed. | [
"Handle",
"takes",
"over",
"responsibility",
"and",
"handles",
"a",
"transport",
".",
"Conn",
".",
"It",
"returns",
"false",
"if",
"the",
"engine",
"is",
"closing",
"and",
"the",
"connection",
"has",
"been",
"closed",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/engine.go#L71-L97 |
132,043 | 256dpi/gomqtt | broker/engine.go | Run | func Run(engine *Engine, protocol string) (string, chan struct{}, chan struct{}) {
// launch server
server, err := transport.Launch(protocol + "://localhost:0")
if err != nil {
panic(err)
}
// prepare channels
quit := make(chan struct{})
done := make(chan struct{})
// start accepting connections
engine.Acc... | go | func Run(engine *Engine, protocol string) (string, chan struct{}, chan struct{}) {
// launch server
server, err := transport.Launch(protocol + "://localhost:0")
if err != nil {
panic(err)
}
// prepare channels
quit := make(chan struct{})
done := make(chan struct{})
// start accepting connections
engine.Acc... | [
"func",
"Run",
"(",
"engine",
"*",
"Engine",
",",
"protocol",
"string",
")",
"(",
"string",
",",
"chan",
"struct",
"{",
"}",
",",
"chan",
"struct",
"{",
"}",
")",
"{",
"// launch server",
"server",
",",
"err",
":=",
"transport",
".",
"Launch",
"(",
"... | // Run runs the passed engine on a random available port and returns a channel
// that can be closed to shutdown the engine. This method is intended to be used
// in testing scenarios. | [
"Run",
"runs",
"the",
"passed",
"engine",
"on",
"a",
"random",
"available",
"port",
"and",
"returns",
"a",
"channel",
"that",
"can",
"be",
"closed",
"to",
"shutdown",
"the",
"engine",
".",
"This",
"method",
"is",
"intended",
"to",
"be",
"used",
"in",
"te... | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/engine.go#L116-L148 |
132,044 | 256dpi/gomqtt | packet/strings.go | readLPBytes | func readLPBytes(buf []byte, safe bool, t Type) ([]byte, int, error) {
if len(buf) < 2 {
return nil, 0, makeError(t, "insufficient buffer size, expected 2, got %d", len(buf))
}
n, total := 0, 0
n = int(binary.BigEndian.Uint16(buf))
total += 2
total += n
if len(buf) < total {
return nil, total, makeError(t... | go | func readLPBytes(buf []byte, safe bool, t Type) ([]byte, int, error) {
if len(buf) < 2 {
return nil, 0, makeError(t, "insufficient buffer size, expected 2, got %d", len(buf))
}
n, total := 0, 0
n = int(binary.BigEndian.Uint16(buf))
total += 2
total += n
if len(buf) < total {
return nil, total, makeError(t... | [
"func",
"readLPBytes",
"(",
"buf",
"[",
"]",
"byte",
",",
"safe",
"bool",
",",
"t",
"Type",
")",
"(",
"[",
"]",
"byte",
",",
"int",
",",
"error",
")",
"{",
"if",
"len",
"(",
"buf",
")",
"<",
"2",
"{",
"return",
"nil",
",",
"0",
",",
"makeErro... | // read length prefixed bytes | [
"read",
"length",
"prefixed",
"bytes"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/packet/strings.go#L10-L33 |
132,045 | 256dpi/gomqtt | packet/strings.go | readLPString | func readLPString(buf []byte, t Type) (string, int, error) {
if len(buf) < 2 {
return "", 0, makeError(t, "insufficient buffer size, expected 2, got %d", len(buf))
}
n, total := 0, 0
n = int(binary.BigEndian.Uint16(buf))
total += 2
total += n
if len(buf) < total {
return "", total, makeError(t, "insuffici... | go | func readLPString(buf []byte, t Type) (string, int, error) {
if len(buf) < 2 {
return "", 0, makeError(t, "insufficient buffer size, expected 2, got %d", len(buf))
}
n, total := 0, 0
n = int(binary.BigEndian.Uint16(buf))
total += 2
total += n
if len(buf) < total {
return "", total, makeError(t, "insuffici... | [
"func",
"readLPString",
"(",
"buf",
"[",
"]",
"byte",
",",
"t",
"Type",
")",
"(",
"string",
",",
"int",
",",
"error",
")",
"{",
"if",
"len",
"(",
"buf",
")",
"<",
"2",
"{",
"return",
"\"",
"\"",
",",
"0",
",",
"makeError",
"(",
"t",
",",
"\""... | // read length prefixed string | [
"read",
"length",
"prefixed",
"string"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/packet/strings.go#L36-L52 |
132,046 | 256dpi/gomqtt | packet/strings.go | writeLPBytes | func writeLPBytes(buf []byte, b []byte, t Type) (int, error) {
total, n := 0, len(b)
if n > int(maxLPLength) {
return 0, makeError(t, "length (%d) greater than %d bytes", n, maxLPLength)
}
if len(buf) < 2+n {
return 0, makeError(t, "insufficient buffer size, expected %d, got %d", 2+n, len(buf))
}
binary.Bi... | go | func writeLPBytes(buf []byte, b []byte, t Type) (int, error) {
total, n := 0, len(b)
if n > int(maxLPLength) {
return 0, makeError(t, "length (%d) greater than %d bytes", n, maxLPLength)
}
if len(buf) < 2+n {
return 0, makeError(t, "insufficient buffer size, expected %d, got %d", 2+n, len(buf))
}
binary.Bi... | [
"func",
"writeLPBytes",
"(",
"buf",
"[",
"]",
"byte",
",",
"b",
"[",
"]",
"byte",
",",
"t",
"Type",
")",
"(",
"int",
",",
"error",
")",
"{",
"total",
",",
"n",
":=",
"0",
",",
"len",
"(",
"b",
")",
"\n\n",
"if",
"n",
">",
"int",
"(",
"maxLP... | // write length prefixed bytes | [
"write",
"length",
"prefixed",
"bytes"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/packet/strings.go#L55-L73 |
132,047 | 256dpi/gomqtt | packet/strings.go | writeLPString | func writeLPString(buf []byte, str string, t Type) (int, error) {
return writeLPBytes(buf, []byte(str), t)
} | go | func writeLPString(buf []byte, str string, t Type) (int, error) {
return writeLPBytes(buf, []byte(str), t)
} | [
"func",
"writeLPString",
"(",
"buf",
"[",
"]",
"byte",
",",
"str",
"string",
",",
"t",
"Type",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"writeLPBytes",
"(",
"buf",
",",
"[",
"]",
"byte",
"(",
"str",
")",
",",
"t",
")",
"\n",
"}"
] | // write length prefixed string | [
"write",
"length",
"prefixed",
"string"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/packet/strings.go#L76-L78 |
132,048 | 256dpi/gomqtt | broker/client.go | NewClient | func NewClient(backend Backend, conn transport.Conn) *Client {
// create client
c := &Client{
state: clientConnecting,
backend: backend,
conn: conn,
done: make(chan struct{}),
}
// start processor
c.tomb.Go(c.processor)
// run cleanup goroutine
go func() {
// wait for death and cleanup
_ = ... | go | func NewClient(backend Backend, conn transport.Conn) *Client {
// create client
c := &Client{
state: clientConnecting,
backend: backend,
conn: conn,
done: make(chan struct{}),
}
// start processor
c.tomb.Go(c.processor)
// run cleanup goroutine
go func() {
// wait for death and cleanup
_ = ... | [
"func",
"NewClient",
"(",
"backend",
"Backend",
",",
"conn",
"transport",
".",
"Conn",
")",
"*",
"Client",
"{",
"// create client",
"c",
":=",
"&",
"Client",
"{",
"state",
":",
"clientConnecting",
",",
"backend",
":",
"backend",
",",
"conn",
":",
"conn",
... | // NewClient takes over a connection and returns a Client. | [
"NewClient",
"takes",
"over",
"a",
"connection",
"and",
"returns",
"a",
"Client",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/client.go#L257-L280 |
132,049 | 256dpi/gomqtt | broker/client.go | Close | func (c *Client) Close() {
_ = c.conn.Close()
c.tomb.Kill(ErrClientClosed)
} | go | func (c *Client) Close() {
_ = c.conn.Close()
c.tomb.Kill(ErrClientClosed)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Close",
"(",
")",
"{",
"_",
"=",
"c",
".",
"conn",
".",
"Close",
"(",
")",
"\n",
"c",
".",
"tomb",
".",
"Kill",
"(",
"ErrClientClosed",
")",
"\n",
"}"
] | // Close will immediately close the client. | [
"Close",
"will",
"immediately",
"close",
"the",
"client",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/client.go#L299-L302 |
132,050 | 256dpi/gomqtt | broker/client.go | processPacket | func (c *Client) processPacket(pkt packet.Generic) error {
// prepare error
var err error
// handle individual packets
switch typedPkt := pkt.(type) {
case *packet.Subscribe:
err = c.processSubscribe(typedPkt)
case *packet.Unsubscribe:
err = c.processUnsubscribe(typedPkt)
case *packet.Publish:
err = c.pro... | go | func (c *Client) processPacket(pkt packet.Generic) error {
// prepare error
var err error
// handle individual packets
switch typedPkt := pkt.(type) {
case *packet.Subscribe:
err = c.processSubscribe(typedPkt)
case *packet.Unsubscribe:
err = c.processUnsubscribe(typedPkt)
case *packet.Publish:
err = c.pro... | [
"func",
"(",
"c",
"*",
"Client",
")",
"processPacket",
"(",
"pkt",
"packet",
".",
"Generic",
")",
"error",
"{",
"// prepare error",
"var",
"err",
"error",
"\n\n",
"// handle individual packets",
"switch",
"typedPkt",
":=",
"pkt",
".",
"(",
"type",
")",
"{",
... | // handle an incoming Generic | [
"handle",
"an",
"incoming",
"Generic"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/client.go#L636-L670 |
132,051 | 256dpi/gomqtt | broker/client.go | processPingreq | func (c *Client) processPingreq() error {
// send a pingresp packet
err := c.send(packet.NewPingresp(), true)
if err != nil {
return c.die(TransportError, err)
}
return nil
} | go | func (c *Client) processPingreq() error {
// send a pingresp packet
err := c.send(packet.NewPingresp(), true)
if err != nil {
return c.die(TransportError, err)
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"processPingreq",
"(",
")",
"error",
"{",
"// send a pingresp packet",
"err",
":=",
"c",
".",
"send",
"(",
"packet",
".",
"NewPingresp",
"(",
")",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
... | // handle an incoming Pingreq packet | [
"handle",
"an",
"incoming",
"Pingreq",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/client.go#L673-L681 |
132,052 | 256dpi/gomqtt | broker/client.go | processSubscribe | func (c *Client) processSubscribe(pkt *packet.Subscribe) error {
// acquire subscribe token
select {
case <-c.subscribeTokens:
// continue
case <-time.After(c.TokenTimeout):
return c.die(ClientError, ErrTokenTimeout)
case <-c.tomb.Dying():
return tomb.ErrDying
}
// prepare suback packet
suback := packet.... | go | func (c *Client) processSubscribe(pkt *packet.Subscribe) error {
// acquire subscribe token
select {
case <-c.subscribeTokens:
// continue
case <-time.After(c.TokenTimeout):
return c.die(ClientError, ErrTokenTimeout)
case <-c.tomb.Dying():
return tomb.ErrDying
}
// prepare suback packet
suback := packet.... | [
"func",
"(",
"c",
"*",
"Client",
")",
"processSubscribe",
"(",
"pkt",
"*",
"packet",
".",
"Subscribe",
")",
"error",
"{",
"// acquire subscribe token",
"select",
"{",
"case",
"<-",
"c",
".",
"subscribeTokens",
":",
"// continue",
"case",
"<-",
"time",
".",
... | // handle an incoming subscribe packet | [
"handle",
"an",
"incoming",
"subscribe",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/client.go#L684-L717 |
132,053 | 256dpi/gomqtt | broker/client.go | processUnsubscribe | func (c *Client) processUnsubscribe(pkt *packet.Unsubscribe) error {
// acquire subscribe token
select {
case <-c.subscribeTokens:
// continue
case <-time.After(c.TokenTimeout):
return c.die(ClientError, ErrTokenTimeout)
case <-c.tomb.Dying():
return tomb.ErrDying
}
// prepare unsuback packet
unsuback :=... | go | func (c *Client) processUnsubscribe(pkt *packet.Unsubscribe) error {
// acquire subscribe token
select {
case <-c.subscribeTokens:
// continue
case <-time.After(c.TokenTimeout):
return c.die(ClientError, ErrTokenTimeout)
case <-c.tomb.Dying():
return tomb.ErrDying
}
// prepare unsuback packet
unsuback :=... | [
"func",
"(",
"c",
"*",
"Client",
")",
"processUnsubscribe",
"(",
"pkt",
"*",
"packet",
".",
"Unsubscribe",
")",
"error",
"{",
"// acquire subscribe token",
"select",
"{",
"case",
"<-",
"c",
".",
"subscribeTokens",
":",
"// continue",
"case",
"<-",
"time",
".... | // handle an incoming unsubscribe packet | [
"handle",
"an",
"incoming",
"unsubscribe",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/client.go#L720-L747 |
132,054 | 256dpi/gomqtt | broker/client.go | processPublish | func (c *Client) processPublish(publish *packet.Publish) error {
// handle qos 0 flow
if publish.Message.QOS == 0 {
// publish message
err := c.backend.Publish(c, &publish.Message, nil)
if err != nil {
return c.die(BackendError, err)
}
c.backend.Log(MessagePublished, c, nil, &publish.Message, nil)
re... | go | func (c *Client) processPublish(publish *packet.Publish) error {
// handle qos 0 flow
if publish.Message.QOS == 0 {
// publish message
err := c.backend.Publish(c, &publish.Message, nil)
if err != nil {
return c.die(BackendError, err)
}
c.backend.Log(MessagePublished, c, nil, &publish.Message, nil)
re... | [
"func",
"(",
"c",
"*",
"Client",
")",
"processPublish",
"(",
"publish",
"*",
"packet",
".",
"Publish",
")",
"error",
"{",
"// handle qos 0 flow",
"if",
"publish",
".",
"Message",
".",
"QOS",
"==",
"0",
"{",
"// publish message",
"err",
":=",
"c",
".",
"b... | // handle an incoming publish packet | [
"handle",
"an",
"incoming",
"publish",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/client.go#L750-L816 |
132,055 | 256dpi/gomqtt | broker/client.go | processPubackAndPubcomp | func (c *Client) processPubackAndPubcomp(id packet.ID) error {
// remove packet from store
err := c.session.DeletePacket(session.Outgoing, id)
if err != nil {
return c.die(SessionError, err)
}
// put back dequeue token
select {
case c.dequeueTokens <- struct{}{}:
default:
// continue if full for some reaso... | go | func (c *Client) processPubackAndPubcomp(id packet.ID) error {
// remove packet from store
err := c.session.DeletePacket(session.Outgoing, id)
if err != nil {
return c.die(SessionError, err)
}
// put back dequeue token
select {
case c.dequeueTokens <- struct{}{}:
default:
// continue if full for some reaso... | [
"func",
"(",
"c",
"*",
"Client",
")",
"processPubackAndPubcomp",
"(",
"id",
"packet",
".",
"ID",
")",
"error",
"{",
"// remove packet from store",
"err",
":=",
"c",
".",
"session",
".",
"DeletePacket",
"(",
"session",
".",
"Outgoing",
",",
"id",
")",
"\n",... | // handle an incoming p or pubcomp packet | [
"handle",
"an",
"incoming",
"p",
"or",
"pubcomp",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/client.go#L819-L834 |
132,056 | 256dpi/gomqtt | broker/client.go | processPubrel | func (c *Client) processPubrel(id packet.ID) error {
// get stored publish packet from session
pkt, err := c.session.LookupPacket(session.Incoming, id)
if err != nil {
return c.die(SessionError, err)
}
// prepare pubcomp packet
pubcomp := packet.NewPubcomp()
pubcomp.ID = id
// get packet from store
publish... | go | func (c *Client) processPubrel(id packet.ID) error {
// get stored publish packet from session
pkt, err := c.session.LookupPacket(session.Incoming, id)
if err != nil {
return c.die(SessionError, err)
}
// prepare pubcomp packet
pubcomp := packet.NewPubcomp()
pubcomp.ID = id
// get packet from store
publish... | [
"func",
"(",
"c",
"*",
"Client",
")",
"processPubrel",
"(",
"id",
"packet",
".",
"ID",
")",
"error",
"{",
"// get stored publish packet from session",
"pkt",
",",
"err",
":=",
"c",
".",
"session",
".",
"LookupPacket",
"(",
"session",
".",
"Incoming",
",",
... | // handle an incoming pubrel packet | [
"handle",
"an",
"incoming",
"pubrel",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/client.go#L858-L897 |
132,057 | 256dpi/gomqtt | broker/client.go | processDisconnect | func (c *Client) processDisconnect() error {
// clear will
c.will = nil
// mark client as cleanly disconnected
atomic.StoreUint32(&c.state, clientDisconnected)
// close underlying connection (triggers cleanup)
_ = c.conn.Close()
// ensure tomb is killed
c.tomb.Kill(ErrClientDisconnected)
c.backend.Log(Clie... | go | func (c *Client) processDisconnect() error {
// clear will
c.will = nil
// mark client as cleanly disconnected
atomic.StoreUint32(&c.state, clientDisconnected)
// close underlying connection (triggers cleanup)
_ = c.conn.Close()
// ensure tomb is killed
c.tomb.Kill(ErrClientDisconnected)
c.backend.Log(Clie... | [
"func",
"(",
"c",
"*",
"Client",
")",
"processDisconnect",
"(",
")",
"error",
"{",
"// clear will",
"c",
".",
"will",
"=",
"nil",
"\n\n",
"// mark client as cleanly disconnected",
"atomic",
".",
"StoreUint32",
"(",
"&",
"c",
".",
"state",
",",
"clientDisconnec... | // handle an incoming disconnect packet | [
"handle",
"an",
"incoming",
"disconnect",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/client.go#L900-L916 |
132,058 | 256dpi/gomqtt | transport/net_server.go | CreateNetServer | func CreateNetServer(address string) (*NetServer, error) {
listener, err := net.Listen("tcp", address)
if err != nil {
return nil, err
}
return NewNetServer(listener), nil
} | go | func CreateNetServer(address string) (*NetServer, error) {
listener, err := net.Listen("tcp", address)
if err != nil {
return nil, err
}
return NewNetServer(listener), nil
} | [
"func",
"CreateNetServer",
"(",
"address",
"string",
")",
"(",
"*",
"NetServer",
",",
"error",
")",
"{",
"listener",
",",
"err",
":=",
"net",
".",
"Listen",
"(",
"\"",
"\"",
",",
"address",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
... | // CreateNetServer creates a new TCP server that listens on the provided address. | [
"CreateNetServer",
"creates",
"a",
"new",
"TCP",
"server",
"that",
"listens",
"on",
"the",
"provided",
"address",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/transport/net_server.go#L24-L31 |
132,059 | 256dpi/gomqtt | transport/net_server.go | CreateSecureNetServer | func CreateSecureNetServer(address string, config *tls.Config) (*NetServer, error) {
listener, err := tls.Listen("tcp", address, config)
if err != nil {
return nil, err
}
return NewNetServer(listener), nil
} | go | func CreateSecureNetServer(address string, config *tls.Config) (*NetServer, error) {
listener, err := tls.Listen("tcp", address, config)
if err != nil {
return nil, err
}
return NewNetServer(listener), nil
} | [
"func",
"CreateSecureNetServer",
"(",
"address",
"string",
",",
"config",
"*",
"tls",
".",
"Config",
")",
"(",
"*",
"NetServer",
",",
"error",
")",
"{",
"listener",
",",
"err",
":=",
"tls",
".",
"Listen",
"(",
"\"",
"\"",
",",
"address",
",",
"config",... | // CreateSecureNetServer creates a new TLS server that listens on the provided address. | [
"CreateSecureNetServer",
"creates",
"a",
"new",
"TLS",
"server",
"that",
"listens",
"on",
"the",
"provided",
"address",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/transport/net_server.go#L34-L41 |
132,060 | 256dpi/gomqtt | client/future/future.go | New | func New() *Future {
return &Future{
Data: new(sync.Map),
completeChannel: make(chan struct{}),
cancelChannel: make(chan struct{}),
}
} | go | func New() *Future {
return &Future{
Data: new(sync.Map),
completeChannel: make(chan struct{}),
cancelChannel: make(chan struct{}),
}
} | [
"func",
"New",
"(",
")",
"*",
"Future",
"{",
"return",
"&",
"Future",
"{",
"Data",
":",
"new",
"(",
"sync",
".",
"Map",
")",
",",
"completeChannel",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"cancelChannel",
":",
"make",
"(",
"chan",
... | // New will return a new Future. | [
"New",
"will",
"return",
"a",
"new",
"Future",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/future/future.go#L26-L32 |
132,061 | 256dpi/gomqtt | client/future/future.go | Bind | func (f *Future) Bind(f2 *Future) {
select {
case <-f2.completeChannel:
f.Data = f2.Data
close(f.completeChannel)
case <-f2.cancelChannel:
f.Data = f2.Data
close(f.cancelChannel)
}
} | go | func (f *Future) Bind(f2 *Future) {
select {
case <-f2.completeChannel:
f.Data = f2.Data
close(f.completeChannel)
case <-f2.cancelChannel:
f.Data = f2.Data
close(f.cancelChannel)
}
} | [
"func",
"(",
"f",
"*",
"Future",
")",
"Bind",
"(",
"f2",
"*",
"Future",
")",
"{",
"select",
"{",
"case",
"<-",
"f2",
".",
"completeChannel",
":",
"f",
".",
"Data",
"=",
"f2",
".",
"Data",
"\n",
"close",
"(",
"f",
".",
"completeChannel",
")",
"\n"... | // Bind will tie the current future to the specified future. If the bound to
// future is completed or canceled the current will as well. Data saved in the
// bound future is copied to the current on complete and cancel. | [
"Bind",
"will",
"tie",
"the",
"current",
"future",
"to",
"the",
"specified",
"future",
".",
"If",
"the",
"bound",
"to",
"future",
"is",
"completed",
"or",
"canceled",
"the",
"current",
"will",
"as",
"well",
".",
"Data",
"saved",
"in",
"the",
"bound",
"fu... | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/future/future.go#L37-L46 |
132,062 | 256dpi/gomqtt | client/future/future.go | Wait | func (f *Future) Wait(timeout time.Duration) error {
select {
case <-f.completeChannel:
return nil
case <-f.cancelChannel:
return ErrCanceled
case <-time.After(timeout):
return ErrTimeout
}
} | go | func (f *Future) Wait(timeout time.Duration) error {
select {
case <-f.completeChannel:
return nil
case <-f.cancelChannel:
return ErrCanceled
case <-time.After(timeout):
return ErrTimeout
}
} | [
"func",
"(",
"f",
"*",
"Future",
")",
"Wait",
"(",
"timeout",
"time",
".",
"Duration",
")",
"error",
"{",
"select",
"{",
"case",
"<-",
"f",
".",
"completeChannel",
":",
"return",
"nil",
"\n",
"case",
"<-",
"f",
".",
"cancelChannel",
":",
"return",
"E... | // Wait will wait the given amount of time and return whether the future has been
// completed, canceled or the request timed out. | [
"Wait",
"will",
"wait",
"the",
"given",
"amount",
"of",
"time",
"and",
"return",
"whether",
"the",
"future",
"has",
"been",
"completed",
"canceled",
"or",
"the",
"request",
"timed",
"out",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/future/future.go#L50-L59 |
132,063 | 256dpi/gomqtt | topic/tree.go | Add | func (t *Tree) Add(topic string, value interface{}) {
t.mutex.Lock()
defer t.mutex.Unlock()
t.add(value, 0, strings.Split(topic, t.Separator), t.root)
} | go | func (t *Tree) Add(topic string, value interface{}) {
t.mutex.Lock()
defer t.mutex.Unlock()
t.add(value, 0, strings.Split(topic, t.Separator), t.root)
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"Add",
"(",
"topic",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"{",
"t",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"t",
".",
"add",
"(... | // Add registers the value for the supplied topic. This function will
// automatically grow the tree. If value already exists for the given topic it
// will not be added again. | [
"Add",
"registers",
"the",
"value",
"for",
"the",
"supplied",
"topic",
".",
"This",
"function",
"will",
"automatically",
"grow",
"the",
"tree",
".",
"If",
"value",
"already",
"exists",
"for",
"the",
"given",
"topic",
"it",
"will",
"not",
"be",
"added",
"ag... | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/topic/tree.go#L78-L83 |
132,064 | 256dpi/gomqtt | topic/tree.go | Set | func (t *Tree) Set(topic string, value interface{}) {
t.mutex.Lock()
defer t.mutex.Unlock()
t.set(value, 0, strings.Split(topic, t.Separator), t.root)
} | go | func (t *Tree) Set(topic string, value interface{}) {
t.mutex.Lock()
defer t.mutex.Unlock()
t.set(value, 0, strings.Split(topic, t.Separator), t.root)
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"Set",
"(",
"topic",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"{",
"t",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"t",
".",
"set",
"(... | // Set sets the supplied value as the only value for the supplied topic. This
// function will automatically grow the tree. | [
"Set",
"sets",
"the",
"supplied",
"value",
"as",
"the",
"only",
"value",
"for",
"the",
"supplied",
"topic",
".",
"This",
"function",
"will",
"automatically",
"grow",
"the",
"tree",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/topic/tree.go#L112-L117 |
132,065 | 256dpi/gomqtt | topic/tree.go | Get | func (t *Tree) Get(topic string) []interface{} {
t.mutex.Lock()
defer t.mutex.Unlock()
return t.get(0, strings.Split(topic, t.Separator), t.root)
} | go | func (t *Tree) Get(topic string) []interface{} {
t.mutex.Lock()
defer t.mutex.Unlock()
return t.get(0, strings.Split(topic, t.Separator), t.root)
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"Get",
"(",
"topic",
"string",
")",
"[",
"]",
"interface",
"{",
"}",
"{",
"t",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"t",
".",
"ge... | // Get gets the values from the topic that exactly matches the supplied topics. | [
"Get",
"gets",
"the",
"values",
"from",
"the",
"topic",
"that",
"exactly",
"matches",
"the",
"supplied",
"topics",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/topic/tree.go#L139-L144 |
132,066 | 256dpi/gomqtt | topic/tree.go | Remove | func (t *Tree) Remove(topic string, value interface{}) {
t.mutex.Lock()
defer t.mutex.Unlock()
t.remove(value, 0, strings.Split(topic, t.Separator), t.root)
} | go | func (t *Tree) Remove(topic string, value interface{}) {
t.mutex.Lock()
defer t.mutex.Unlock()
t.remove(value, 0, strings.Split(topic, t.Separator), t.root)
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"Remove",
"(",
"topic",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"{",
"t",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"t",
".",
"remove"... | // Remove un-registers the value from the supplied topic. This function will
// automatically shrink the tree. | [
"Remove",
"un",
"-",
"registers",
"the",
"value",
"from",
"the",
"supplied",
"topic",
".",
"This",
"function",
"will",
"automatically",
"shrink",
"the",
"tree",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/topic/tree.go#L164-L169 |
132,067 | 256dpi/gomqtt | topic/tree.go | Empty | func (t *Tree) Empty(topic string) {
t.mutex.Lock()
defer t.mutex.Unlock()
t.remove(nil, 0, strings.Split(topic, t.Separator), t.root)
} | go | func (t *Tree) Empty(topic string) {
t.mutex.Lock()
defer t.mutex.Unlock()
t.remove(nil, 0, strings.Split(topic, t.Separator), t.root)
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"Empty",
"(",
"topic",
"string",
")",
"{",
"t",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"t",
".",
"remove",
"(",
"nil",
",",
"0",
",",
"string... | // Empty will unregister all values from the supplied topic. This function will
// automatically shrink the tree. | [
"Empty",
"will",
"unregister",
"all",
"values",
"from",
"the",
"supplied",
"topic",
".",
"This",
"function",
"will",
"automatically",
"shrink",
"the",
"tree",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/topic/tree.go#L173-L178 |
132,068 | 256dpi/gomqtt | topic/tree.go | Clear | func (t *Tree) Clear(value interface{}) {
t.mutex.Lock()
defer t.mutex.Unlock()
t.clear(value, t.root)
} | go | func (t *Tree) Clear(value interface{}) {
t.mutex.Lock()
defer t.mutex.Unlock()
t.clear(value, t.root)
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"Clear",
"(",
"value",
"interface",
"{",
"}",
")",
"{",
"t",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"t",
".",
"clear",
"(",
"value",
",",
"t"... | // Clear will unregister the supplied value from all topics. This function will
// automatically shrink the tree. | [
"Clear",
"will",
"unregister",
"the",
"supplied",
"value",
"from",
"all",
"topics",
".",
"This",
"function",
"will",
"automatically",
"shrink",
"the",
"tree",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/topic/tree.go#L209-L214 |
132,069 | 256dpi/gomqtt | topic/tree.go | MatchFirst | func (t *Tree) MatchFirst(topic string) interface{} {
values := t.Match(topic)
if len(values) > 0 {
return values[0]
}
return nil
} | go | func (t *Tree) MatchFirst(topic string) interface{} {
values := t.Match(topic)
if len(values) > 0 {
return values[0]
}
return nil
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"MatchFirst",
"(",
"topic",
"string",
")",
"interface",
"{",
"}",
"{",
"values",
":=",
"t",
".",
"Match",
"(",
"topic",
")",
"\n\n",
"if",
"len",
"(",
"values",
")",
">",
"0",
"{",
"return",
"values",
"[",
"0",... | // MatchFirst will run Match and return the first value or nil. | [
"MatchFirst",
"will",
"run",
"Match",
"and",
"return",
"the",
"first",
"value",
"or",
"nil",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/topic/tree.go#L273-L281 |
132,070 | 256dpi/gomqtt | topic/tree.go | SearchFirst | func (t *Tree) SearchFirst(topic string) interface{} {
values := t.Search(topic)
if len(values) > 0 {
return values[0]
}
return nil
} | go | func (t *Tree) SearchFirst(topic string) interface{} {
values := t.Search(topic)
if len(values) > 0 {
return values[0]
}
return nil
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"SearchFirst",
"(",
"topic",
"string",
")",
"interface",
"{",
"}",
"{",
"values",
":=",
"t",
".",
"Search",
"(",
"topic",
")",
"\n\n",
"if",
"len",
"(",
"values",
")",
">",
"0",
"{",
"return",
"values",
"[",
"0... | // SearchFirst will run Search and return the first value or nil. | [
"SearchFirst",
"will",
"run",
"Search",
"and",
"return",
"the",
"first",
"value",
"or",
"nil",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/topic/tree.go#L336-L344 |
132,071 | 256dpi/gomqtt | topic/tree.go | clean | func (t *Tree) clean(values []interface{}) []interface{} {
result := values[:0]
for _, v := range values {
if contains(result, v) {
continue
}
result = append(result, v)
}
return result
} | go | func (t *Tree) clean(values []interface{}) []interface{} {
result := values[:0]
for _, v := range values {
if contains(result, v) {
continue
}
result = append(result, v)
}
return result
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"clean",
"(",
"values",
"[",
"]",
"interface",
"{",
"}",
")",
"[",
"]",
"interface",
"{",
"}",
"{",
"result",
":=",
"values",
"[",
":",
"0",
"]",
"\n\n",
"for",
"_",
",",
"v",
":=",
"range",
"values",
"{",
... | // clean will remove duplicates | [
"clean",
"will",
"remove",
"duplicates"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/topic/tree.go#L347-L359 |
132,072 | 256dpi/gomqtt | topic/tree.go | All | func (t *Tree) All() []interface{} {
t.mutex.RLock()
defer t.mutex.RUnlock()
return t.clean(t.all([]interface{}{}, t.root))
} | go | func (t *Tree) All() []interface{} {
t.mutex.RLock()
defer t.mutex.RUnlock()
return t.clean(t.all([]interface{}{}, t.root))
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"All",
"(",
")",
"[",
"]",
"interface",
"{",
"}",
"{",
"t",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"defer",
"t",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"t",
".",
"clean",
"(",
"t",
... | // All will return all stored values in the tree. | [
"All",
"will",
"return",
"all",
"stored",
"values",
"in",
"the",
"tree",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/topic/tree.go#L384-L389 |
132,073 | 256dpi/gomqtt | topic/tree.go | Reset | func (t *Tree) Reset() {
t.mutex.Lock()
defer t.mutex.Unlock()
t.root = newNode()
} | go | func (t *Tree) Reset() {
t.mutex.Lock()
defer t.mutex.Unlock()
t.root = newNode()
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"Reset",
"(",
")",
"{",
"t",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"t",
".",
"root",
"=",
"newNode",
"(",
")",
"\n",
"}"
] | // Reset will completely clear the tree. | [
"Reset",
"will",
"completely",
"clear",
"the",
"tree",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/topic/tree.go#L402-L407 |
132,074 | 256dpi/gomqtt | topic/tree.go | String | func (t *Tree) String() string {
t.mutex.RLock()
defer t.mutex.RUnlock()
return fmt.Sprintf("topic.Tree:%s", t.root.string(0))
} | go | func (t *Tree) String() string {
t.mutex.RLock()
defer t.mutex.RUnlock()
return fmt.Sprintf("topic.Tree:%s", t.root.string(0))
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"String",
"(",
")",
"string",
"{",
"t",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"defer",
"t",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
... | // String will return a string representation of the tree. | [
"String",
"will",
"return",
"a",
"string",
"representation",
"of",
"the",
"tree",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/topic/tree.go#L410-L415 |
132,075 | 256dpi/gomqtt | spec/spec.go | AllFeatures | func AllFeatures() *Config {
return &Config{
RetainedMessages: true,
StoredPackets: true,
StoredSubscriptions: true,
OfflineSubscriptions: true,
Authentication: true,
UniqueClientIDs: true,
RootSlashDistinction: true,
}
} | go | func AllFeatures() *Config {
return &Config{
RetainedMessages: true,
StoredPackets: true,
StoredSubscriptions: true,
OfflineSubscriptions: true,
Authentication: true,
UniqueClientIDs: true,
RootSlashDistinction: true,
}
} | [
"func",
"AllFeatures",
"(",
")",
"*",
"Config",
"{",
"return",
"&",
"Config",
"{",
"RetainedMessages",
":",
"true",
",",
"StoredPackets",
":",
"true",
",",
"StoredSubscriptions",
":",
"true",
",",
"OfflineSubscriptions",
":",
"true",
",",
"Authentication",
":"... | // AllFeatures returns a config that enables all features. | [
"AllFeatures",
"returns",
"a",
"config",
"that",
"enables",
"all",
"features",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/spec/spec.go#L43-L53 |
132,076 | 256dpi/gomqtt | packet/type.go | String | func (t Type) String() string {
switch t {
case CONNECT:
return "Connect"
case CONNACK:
return "Connack"
case PUBLISH:
return "Publish"
case PUBACK:
return "Puback"
case PUBREC:
return "Pubrec"
case PUBREL:
return "Pubrel"
case PUBCOMP:
return "Pubcomp"
case SUBSCRIBE:
return "Subscribe"
case ... | go | func (t Type) String() string {
switch t {
case CONNECT:
return "Connect"
case CONNACK:
return "Connack"
case PUBLISH:
return "Publish"
case PUBACK:
return "Puback"
case PUBREC:
return "Pubrec"
case PUBREL:
return "Pubrel"
case PUBCOMP:
return "Pubcomp"
case SUBSCRIBE:
return "Subscribe"
case ... | [
"func",
"(",
"t",
"Type",
")",
"String",
"(",
")",
"string",
"{",
"switch",
"t",
"{",
"case",
"CONNECT",
":",
"return",
"\"",
"\"",
"\n",
"case",
"CONNACK",
":",
"return",
"\"",
"\"",
"\n",
"case",
"PUBLISH",
":",
"return",
"\"",
"\"",
"\n",
"case"... | // String returns the type as a string. | [
"String",
"returns",
"the",
"type",
"as",
"a",
"string",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/packet/type.go#L31-L64 |
132,077 | 256dpi/gomqtt | packet/type.go | defaultFlags | func (t Type) defaultFlags() byte {
switch t {
case CONNECT:
return 0
case CONNACK:
return 0
case PUBACK:
return 0
case PUBREC:
return 0
case PUBREL:
return 2 // 00000010
case PUBCOMP:
return 0
case SUBSCRIBE:
return 2 // 00000010
case SUBACK:
return 0
case UNSUBSCRIBE:
return 2 // 00000010
... | go | func (t Type) defaultFlags() byte {
switch t {
case CONNECT:
return 0
case CONNACK:
return 0
case PUBACK:
return 0
case PUBREC:
return 0
case PUBREL:
return 2 // 00000010
case PUBCOMP:
return 0
case SUBSCRIBE:
return 2 // 00000010
case SUBACK:
return 0
case UNSUBSCRIBE:
return 2 // 00000010
... | [
"func",
"(",
"t",
"Type",
")",
"defaultFlags",
"(",
")",
"byte",
"{",
"switch",
"t",
"{",
"case",
"CONNECT",
":",
"return",
"0",
"\n",
"case",
"CONNACK",
":",
"return",
"0",
"\n",
"case",
"PUBACK",
":",
"return",
"0",
"\n",
"case",
"PUBREC",
":",
"... | // DefaultFlags returns the default flag values for the packet type, as defined
// by the MQTT spec, except for PUBLISH. | [
"DefaultFlags",
"returns",
"the",
"default",
"flag",
"values",
"for",
"the",
"packet",
"type",
"as",
"defined",
"by",
"the",
"MQTT",
"spec",
"except",
"for",
"PUBLISH",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/packet/type.go#L68-L99 |
132,078 | 256dpi/gomqtt | transport/websocket_server.go | NewWebSocketServer | func NewWebSocketServer(listener net.Listener) *WebSocketServer {
// create server
ws := &WebSocketServer{
listener: listener,
upgrader: &websocket.Upgrader{
HandshakeTimeout: 60 * time.Second,
Subprotocols: []string{"mqtt", "mqttv3.1"},
},
incoming: make(chan *WebSocketConn),
}
// add check orig... | go | func NewWebSocketServer(listener net.Listener) *WebSocketServer {
// create server
ws := &WebSocketServer{
listener: listener,
upgrader: &websocket.Upgrader{
HandshakeTimeout: 60 * time.Second,
Subprotocols: []string{"mqtt", "mqttv3.1"},
},
incoming: make(chan *WebSocketConn),
}
// add check orig... | [
"func",
"NewWebSocketServer",
"(",
"listener",
"net",
".",
"Listener",
")",
"*",
"WebSocketServer",
"{",
"// create server",
"ws",
":=",
"&",
"WebSocketServer",
"{",
"listener",
":",
"listener",
",",
"upgrader",
":",
"&",
"websocket",
".",
"Upgrader",
"{",
"Ha... | // NewWebSocketServer wraps the provided listener. | [
"NewWebSocketServer",
"wraps",
"the",
"provided",
"listener",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/transport/websocket_server.go#L31-L62 |
132,079 | 256dpi/gomqtt | transport/websocket_server.go | CreateWebSocketServer | func CreateWebSocketServer(address string) (*WebSocketServer, error) {
listener, err := net.Listen("tcp", address)
if err != nil {
return nil, err
}
return NewWebSocketServer(listener), nil
} | go | func CreateWebSocketServer(address string) (*WebSocketServer, error) {
listener, err := net.Listen("tcp", address)
if err != nil {
return nil, err
}
return NewWebSocketServer(listener), nil
} | [
"func",
"CreateWebSocketServer",
"(",
"address",
"string",
")",
"(",
"*",
"WebSocketServer",
",",
"error",
")",
"{",
"listener",
",",
"err",
":=",
"net",
".",
"Listen",
"(",
"\"",
"\"",
",",
"address",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return"... | // CreateWebSocketServer creates a new WS server that listens on the provided address. | [
"CreateWebSocketServer",
"creates",
"a",
"new",
"WS",
"server",
"that",
"listens",
"on",
"the",
"provided",
"address",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/transport/websocket_server.go#L65-L72 |
132,080 | 256dpi/gomqtt | transport/websocket_server.go | CreateSecureWebSocketServer | func CreateSecureWebSocketServer(address string, config *tls.Config) (*WebSocketServer, error) {
listener, err := tls.Listen("tcp", address, config)
if err != nil {
return nil, err
}
return NewWebSocketServer(listener), nil
} | go | func CreateSecureWebSocketServer(address string, config *tls.Config) (*WebSocketServer, error) {
listener, err := tls.Listen("tcp", address, config)
if err != nil {
return nil, err
}
return NewWebSocketServer(listener), nil
} | [
"func",
"CreateSecureWebSocketServer",
"(",
"address",
"string",
",",
"config",
"*",
"tls",
".",
"Config",
")",
"(",
"*",
"WebSocketServer",
",",
"error",
")",
"{",
"listener",
",",
"err",
":=",
"tls",
".",
"Listen",
"(",
"\"",
"\"",
",",
"address",
",",... | // CreateSecureWebSocketServer creates a new WSS server that listens on the
// provided address. | [
"CreateSecureWebSocketServer",
"creates",
"a",
"new",
"WSS",
"server",
"that",
"listens",
"on",
"the",
"provided",
"address",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/transport/websocket_server.go#L76-L83 |
132,081 | 256dpi/gomqtt | transport/websocket_server.go | SetOriginChecker | func (s *WebSocketServer) SetOriginChecker(fn func(r *http.Request) bool) {
s.originChecker = fn
} | go | func (s *WebSocketServer) SetOriginChecker(fn func(r *http.Request) bool) {
s.originChecker = fn
} | [
"func",
"(",
"s",
"*",
"WebSocketServer",
")",
"SetOriginChecker",
"(",
"fn",
"func",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"bool",
")",
"{",
"s",
".",
"originChecker",
"=",
"fn",
"\n",
"}"
] | // SetOriginChecker sets an optional function that allows check the request origin
// before accepting the connection. | [
"SetOriginChecker",
"sets",
"an",
"optional",
"function",
"that",
"allows",
"check",
"the",
"request",
"origin",
"before",
"accepting",
"the",
"connection",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/transport/websocket_server.go#L93-L95 |
132,082 | 256dpi/gomqtt | client/service.go | NewService | func NewService(queueSize ...int) *Service {
var qs = 100
if len(queueSize) > 0 {
qs = queueSize[0]
}
return &Service{
state: serviceStopped,
Session: session.NewMemorySession(),
MinReconnectDelay: 50 * time.Millisecond,
MaxReconnectDelay: 10 ... | go | func NewService(queueSize ...int) *Service {
var qs = 100
if len(queueSize) > 0 {
qs = queueSize[0]
}
return &Service{
state: serviceStopped,
Session: session.NewMemorySession(),
MinReconnectDelay: 50 * time.Millisecond,
MaxReconnectDelay: 10 ... | [
"func",
"NewService",
"(",
"queueSize",
"...",
"int",
")",
"*",
"Service",
"{",
"var",
"qs",
"=",
"100",
"\n",
"if",
"len",
"(",
"queueSize",
")",
">",
"0",
"{",
"qs",
"=",
"queueSize",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"return",
"&",
"Service",
... | // NewService allocates and returns a new service. The optional parameter queueSize
// specifies how many Subscribe, Unsubscribe and Publish commands can be queued
// up before actually sending them on the wire. The default queueSize is 100. | [
"NewService",
"allocates",
"and",
"returns",
"a",
"new",
"service",
".",
"The",
"optional",
"parameter",
"queueSize",
"specifies",
"how",
"many",
"Subscribe",
"Unsubscribe",
"and",
"Publish",
"commands",
"can",
"be",
"queued",
"up",
"before",
"actually",
"sending"... | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/service.go#L131-L150 |
132,083 | 256dpi/gomqtt | client/service.go | Start | func (s *Service) Start(config *Config) {
if config == nil {
panic("no config specified")
}
s.mutex.Lock()
defer s.mutex.Unlock()
// return if already started
if atomic.LoadUint32(&s.state) == serviceStarted {
return
}
// set state
atomic.StoreUint32(&s.state, serviceStarted)
// save config
s.config ... | go | func (s *Service) Start(config *Config) {
if config == nil {
panic("no config specified")
}
s.mutex.Lock()
defer s.mutex.Unlock()
// return if already started
if atomic.LoadUint32(&s.state) == serviceStarted {
return
}
// set state
atomic.StoreUint32(&s.state, serviceStarted)
// save config
s.config ... | [
"func",
"(",
"s",
"*",
"Service",
")",
"Start",
"(",
"config",
"*",
"Config",
")",
"{",
"if",
"config",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"s",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu... | // Start will start the service with the specified configuration. From now on
// the service will automatically reconnect on any error until Stop is called. | [
"Start",
"will",
"start",
"the",
"service",
"with",
"the",
"specified",
"configuration",
".",
"From",
"now",
"on",
"the",
"service",
"will",
"automatically",
"reconnect",
"on",
"any",
"error",
"until",
"Stop",
"is",
"called",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/service.go#L154-L188 |
132,084 | 256dpi/gomqtt | client/service.go | PublishMessage | func (s *Service) PublishMessage(msg *packet.Message) GenericFuture {
s.mutex.Lock()
defer s.mutex.Unlock()
// allocate future
f := future.New()
// queue publish
s.commandQueue <- &command{
publish: true,
future: f,
message: msg,
}
return f
} | go | func (s *Service) PublishMessage(msg *packet.Message) GenericFuture {
s.mutex.Lock()
defer s.mutex.Unlock()
// allocate future
f := future.New()
// queue publish
s.commandQueue <- &command{
publish: true,
future: f,
message: msg,
}
return f
} | [
"func",
"(",
"s",
"*",
"Service",
")",
"PublishMessage",
"(",
"msg",
"*",
"packet",
".",
"Message",
")",
"GenericFuture",
"{",
"s",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// allocate f... | // PublishMessage will send a Publish packet containing the passed message. It will
// return a PublishFuture that gets completed once the quality of service flow
// has been completed. | [
"PublishMessage",
"will",
"send",
"a",
"Publish",
"packet",
"containing",
"the",
"passed",
"message",
".",
"It",
"will",
"return",
"a",
"PublishFuture",
"that",
"gets",
"completed",
"once",
"the",
"quality",
"of",
"service",
"flow",
"has",
"been",
"completed",
... | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/service.go#L207-L222 |
132,085 | 256dpi/gomqtt | client/service.go | Subscribe | func (s *Service) Subscribe(topic string, qos packet.QOS) SubscribeFuture {
return s.SubscribeMultiple([]packet.Subscription{
{Topic: topic, QOS: qos},
})
} | go | func (s *Service) Subscribe(topic string, qos packet.QOS) SubscribeFuture {
return s.SubscribeMultiple([]packet.Subscription{
{Topic: topic, QOS: qos},
})
} | [
"func",
"(",
"s",
"*",
"Service",
")",
"Subscribe",
"(",
"topic",
"string",
",",
"qos",
"packet",
".",
"QOS",
")",
"SubscribeFuture",
"{",
"return",
"s",
".",
"SubscribeMultiple",
"(",
"[",
"]",
"packet",
".",
"Subscription",
"{",
"{",
"Topic",
":",
"t... | // Subscribe will send a Subscribe packet containing one topic to subscribe. It
// will return a SubscribeFuture that gets completed once the acknowledgements
// have been received. | [
"Subscribe",
"will",
"send",
"a",
"Subscribe",
"packet",
"containing",
"one",
"topic",
"to",
"subscribe",
".",
"It",
"will",
"return",
"a",
"SubscribeFuture",
"that",
"gets",
"completed",
"once",
"the",
"acknowledgements",
"have",
"been",
"received",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/service.go#L227-L231 |
132,086 | 256dpi/gomqtt | client/service.go | SubscribeMultiple | func (s *Service) SubscribeMultiple(subscriptions []packet.Subscription) SubscribeFuture {
s.mutex.Lock()
defer s.mutex.Unlock()
// save subscription
for _, v := range subscriptions {
s.subscriptions.Set(v.Topic, v)
}
// allocate future
f := future.New()
// queue subscribe
s.commandQueue <- &command{
su... | go | func (s *Service) SubscribeMultiple(subscriptions []packet.Subscription) SubscribeFuture {
s.mutex.Lock()
defer s.mutex.Unlock()
// save subscription
for _, v := range subscriptions {
s.subscriptions.Set(v.Topic, v)
}
// allocate future
f := future.New()
// queue subscribe
s.commandQueue <- &command{
su... | [
"func",
"(",
"s",
"*",
"Service",
")",
"SubscribeMultiple",
"(",
"subscriptions",
"[",
"]",
"packet",
".",
"Subscription",
")",
"SubscribeFuture",
"{",
"s",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mutex",
".",
"Unlock",
"(",
")",... | // SubscribeMultiple will send a Subscribe packet containing multiple topics to
// subscribe. It will return a SubscribeFuture that gets completed once the
// acknowledgements have been received. | [
"SubscribeMultiple",
"will",
"send",
"a",
"Subscribe",
"packet",
"containing",
"multiple",
"topics",
"to",
"subscribe",
".",
"It",
"will",
"return",
"a",
"SubscribeFuture",
"that",
"gets",
"completed",
"once",
"the",
"acknowledgements",
"have",
"been",
"received",
... | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/service.go#L236-L256 |
132,087 | 256dpi/gomqtt | client/service.go | Unsubscribe | func (s *Service) Unsubscribe(topic string) GenericFuture {
return s.UnsubscribeMultiple([]string{topic})
} | go | func (s *Service) Unsubscribe(topic string) GenericFuture {
return s.UnsubscribeMultiple([]string{topic})
} | [
"func",
"(",
"s",
"*",
"Service",
")",
"Unsubscribe",
"(",
"topic",
"string",
")",
"GenericFuture",
"{",
"return",
"s",
".",
"UnsubscribeMultiple",
"(",
"[",
"]",
"string",
"{",
"topic",
"}",
")",
"\n",
"}"
] | // Unsubscribe will send a Unsubscribe packet containing one topic to unsubscribe.
// It will return a SubscribeFuture that gets completed once the acknowledgements
// have been received. | [
"Unsubscribe",
"will",
"send",
"a",
"Unsubscribe",
"packet",
"containing",
"one",
"topic",
"to",
"unsubscribe",
".",
"It",
"will",
"return",
"a",
"SubscribeFuture",
"that",
"gets",
"completed",
"once",
"the",
"acknowledgements",
"have",
"been",
"received",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/service.go#L261-L263 |
132,088 | 256dpi/gomqtt | client/service.go | UnsubscribeMultiple | func (s *Service) UnsubscribeMultiple(topics []string) GenericFuture {
s.mutex.Lock()
defer s.mutex.Unlock()
// remove subscription
for _, v := range topics {
s.subscriptions.Empty(v)
}
// allocate future
f := future.New()
// queue unsubscribe
s.commandQueue <- &command{
unsubscribe: true,
future: ... | go | func (s *Service) UnsubscribeMultiple(topics []string) GenericFuture {
s.mutex.Lock()
defer s.mutex.Unlock()
// remove subscription
for _, v := range topics {
s.subscriptions.Empty(v)
}
// allocate future
f := future.New()
// queue unsubscribe
s.commandQueue <- &command{
unsubscribe: true,
future: ... | [
"func",
"(",
"s",
"*",
"Service",
")",
"UnsubscribeMultiple",
"(",
"topics",
"[",
"]",
"string",
")",
"GenericFuture",
"{",
"s",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// remove subscrip... | // UnsubscribeMultiple will send a Unsubscribe packet containing multiple
// topics to unsubscribe. It will return a SubscribeFuture that gets completed
// once the acknowledgements have been received. | [
"UnsubscribeMultiple",
"will",
"send",
"a",
"Unsubscribe",
"packet",
"containing",
"multiple",
"topics",
"to",
"unsubscribe",
".",
"It",
"will",
"return",
"a",
"SubscribeFuture",
"that",
"gets",
"completed",
"once",
"the",
"acknowledgements",
"have",
"been",
"receiv... | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/service.go#L268-L288 |
132,089 | 256dpi/gomqtt | client/service.go | supervisor | func (s *Service) supervisor() error {
first := true
for {
if first {
// no delay on first attempt
first = false
} else {
// get backoff duration
d := s.backoff.Duration()
s.log(fmt.Sprintf("Delay Reconnect: %v", d))
// sleep but return on Stop
select {
case <-time.After(d):
case <-s.... | go | func (s *Service) supervisor() error {
first := true
for {
if first {
// no delay on first attempt
first = false
} else {
// get backoff duration
d := s.backoff.Duration()
s.log(fmt.Sprintf("Delay Reconnect: %v", d))
// sleep but return on Stop
select {
case <-time.After(d):
case <-s.... | [
"func",
"(",
"s",
"*",
"Service",
")",
"supervisor",
"(",
")",
"error",
"{",
"first",
":=",
"true",
"\n\n",
"for",
"{",
"if",
"first",
"{",
"// no delay on first attempt",
"first",
"=",
"false",
"\n",
"}",
"else",
"{",
"// get backoff duration",
"d",
":=",... | // the supervised reconnect loop | [
"the",
"supervised",
"reconnect",
"loop"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/service.go#L319-L375 |
132,090 | 256dpi/gomqtt | client/service.go | connect | func (s *Service) connect(fail chan struct{}) (*Client, bool) {
// prepare new client
client := New()
client.Session = s.Session
client.Logger = s.Logger
client.futureStore = s.futureStore
// set callback
client.Callback = func(msg *packet.Message, err error) error {
if err != nil {
s.err("Client", err)
... | go | func (s *Service) connect(fail chan struct{}) (*Client, bool) {
// prepare new client
client := New()
client.Session = s.Session
client.Logger = s.Logger
client.futureStore = s.futureStore
// set callback
client.Callback = func(msg *packet.Message, err error) error {
if err != nil {
s.err("Client", err)
... | [
"func",
"(",
"s",
"*",
"Service",
")",
"connect",
"(",
"fail",
"chan",
"struct",
"{",
"}",
")",
"(",
"*",
"Client",
",",
"bool",
")",
"{",
"// prepare new client",
"client",
":=",
"New",
"(",
")",
"\n",
"client",
".",
"Session",
"=",
"s",
".",
"Ses... | // will try to connect one client to the broker | [
"will",
"try",
"to",
"connect",
"one",
"client",
"to",
"the",
"broker"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/service.go#L378-L426 |
132,091 | 256dpi/gomqtt | client/service.go | dispatcher | func (s *Service) dispatcher(client *Client, fail chan struct{}) bool {
for {
select {
case cmd := <-s.commandQueue:
// handle subscribe command
if cmd.subscribe {
f2, err := client.SubscribeMultiple(cmd.subscriptions)
if err != nil {
s.err("Subscribe", err)
// cancel future
cmd.futu... | go | func (s *Service) dispatcher(client *Client, fail chan struct{}) bool {
for {
select {
case cmd := <-s.commandQueue:
// handle subscribe command
if cmd.subscribe {
f2, err := client.SubscribeMultiple(cmd.subscriptions)
if err != nil {
s.err("Subscribe", err)
// cancel future
cmd.futu... | [
"func",
"(",
"s",
"*",
"Service",
")",
"dispatcher",
"(",
"client",
"*",
"Client",
",",
"fail",
"chan",
"struct",
"{",
"}",
")",
"bool",
"{",
"for",
"{",
"select",
"{",
"case",
"cmd",
":=",
"<-",
"s",
".",
"commandQueue",
":",
"// handle subscribe comm... | // reads from the queues and calls the current client | [
"reads",
"from",
"the",
"queues",
"and",
"calls",
"the",
"current",
"client"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/service.go#L474-L541 |
132,092 | 256dpi/gomqtt | packet/connack.go | String | func (cc ConnackCode) String() string {
switch cc {
case ConnectionAccepted:
return "connection accepted"
case InvalidProtocolVersion:
return "connection refused: unacceptable protocol version"
case IdentifierRejected:
return "connection refused: identifier rejected"
case ServerUnavailable:
return "connect... | go | func (cc ConnackCode) String() string {
switch cc {
case ConnectionAccepted:
return "connection accepted"
case InvalidProtocolVersion:
return "connection refused: unacceptable protocol version"
case IdentifierRejected:
return "connection refused: identifier rejected"
case ServerUnavailable:
return "connect... | [
"func",
"(",
"cc",
"ConnackCode",
")",
"String",
"(",
")",
"string",
"{",
"switch",
"cc",
"{",
"case",
"ConnectionAccepted",
":",
"return",
"\"",
"\"",
"\n",
"case",
"InvalidProtocolVersion",
":",
"return",
"\"",
"\"",
"\n",
"case",
"IdentifierRejected",
":"... | // String returns the corresponding error string for the ConnackCode. | [
"String",
"returns",
"the",
"corresponding",
"error",
"string",
"for",
"the",
"ConnackCode",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/packet/connack.go#L24-L41 |
132,093 | 256dpi/gomqtt | client/tools.go | ClearSession | func ClearSession(config *Config, timeout time.Duration) error {
// copy config
newConfig := *config
newConfig.CleanSession = true
// create client
client := New()
// connect to broker
future, err := client.Connect(&newConfig)
if err != nil {
return err
}
// wait for future
err = future.Wait(timeout)
i... | go | func ClearSession(config *Config, timeout time.Duration) error {
// copy config
newConfig := *config
newConfig.CleanSession = true
// create client
client := New()
// connect to broker
future, err := client.Connect(&newConfig)
if err != nil {
return err
}
// wait for future
err = future.Wait(timeout)
i... | [
"func",
"ClearSession",
"(",
"config",
"*",
"Config",
",",
"timeout",
"time",
".",
"Duration",
")",
"error",
"{",
"// copy config",
"newConfig",
":=",
"*",
"config",
"\n",
"newConfig",
".",
"CleanSession",
"=",
"true",
"\n\n",
"// create client",
"client",
":=... | // ClearSession will connect to the specified broker and request a clean session. | [
"ClearSession",
"will",
"connect",
"to",
"the",
"specified",
"broker",
"and",
"request",
"a",
"clean",
"session",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/tools.go#L10-L37 |
132,094 | 256dpi/gomqtt | client/tools.go | PublishMessage | func PublishMessage(config *Config, msg *packet.Message, timeout time.Duration) error {
// create client
client := New()
// connect to broker
future, err := client.Connect(config)
if err != nil {
return err
}
// wait on future
err = future.Wait(timeout)
if err != nil {
return err
}
// publish message
... | go | func PublishMessage(config *Config, msg *packet.Message, timeout time.Duration) error {
// create client
client := New()
// connect to broker
future, err := client.Connect(config)
if err != nil {
return err
}
// wait on future
err = future.Wait(timeout)
if err != nil {
return err
}
// publish message
... | [
"func",
"PublishMessage",
"(",
"config",
"*",
"Config",
",",
"msg",
"*",
"packet",
".",
"Message",
",",
"timeout",
"time",
".",
"Duration",
")",
"error",
"{",
"// create client",
"client",
":=",
"New",
"(",
")",
"\n\n",
"// connect to broker",
"future",
",",... | // PublishMessage will connect to the specified broker to publish the passed message. | [
"PublishMessage",
"will",
"connect",
"to",
"the",
"specified",
"broker",
"to",
"publish",
"the",
"passed",
"message",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/tools.go#L40-L75 |
132,095 | 256dpi/gomqtt | client/tools.go | ClearRetainedMessage | func ClearRetainedMessage(config *Config, topic string, timeout time.Duration) error {
return PublishMessage(config, &packet.Message{
Topic: topic,
Payload: nil,
QOS: 0,
Retain: true,
}, timeout)
} | go | func ClearRetainedMessage(config *Config, topic string, timeout time.Duration) error {
return PublishMessage(config, &packet.Message{
Topic: topic,
Payload: nil,
QOS: 0,
Retain: true,
}, timeout)
} | [
"func",
"ClearRetainedMessage",
"(",
"config",
"*",
"Config",
",",
"topic",
"string",
",",
"timeout",
"time",
".",
"Duration",
")",
"error",
"{",
"return",
"PublishMessage",
"(",
"config",
",",
"&",
"packet",
".",
"Message",
"{",
"Topic",
":",
"topic",
","... | // ClearRetainedMessage will connect to the specified broker and send an empty
// retained message to force any already retained message to be cleared. | [
"ClearRetainedMessage",
"will",
"connect",
"to",
"the",
"specified",
"broker",
"and",
"send",
"an",
"empty",
"retained",
"message",
"to",
"force",
"any",
"already",
"retained",
"message",
"to",
"be",
"cleared",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/tools.go#L79-L86 |
132,096 | 256dpi/gomqtt | client/tools.go | ReceiveMessage | func ReceiveMessage(config *Config, topic string, qos packet.QOS, timeout time.Duration) (*packet.Message, error) {
// create client
client := New()
// connect to broker
future, err := client.Connect(config)
if err != nil {
return nil, err
}
// wait for future
err = future.Wait(timeout)
if err != nil {
r... | go | func ReceiveMessage(config *Config, topic string, qos packet.QOS, timeout time.Duration) (*packet.Message, error) {
// create client
client := New()
// connect to broker
future, err := client.Connect(config)
if err != nil {
return nil, err
}
// wait for future
err = future.Wait(timeout)
if err != nil {
r... | [
"func",
"ReceiveMessage",
"(",
"config",
"*",
"Config",
",",
"topic",
"string",
",",
"qos",
"packet",
".",
"QOS",
",",
"timeout",
"time",
".",
"Duration",
")",
"(",
"*",
"packet",
".",
"Message",
",",
"error",
")",
"{",
"// create client",
"client",
":="... | // ReceiveMessage will connect to the specified broker and issue a subscription
// for the specified topic and return the first message received. | [
"ReceiveMessage",
"will",
"connect",
"to",
"the",
"specified",
"broker",
"and",
"issue",
"a",
"subscription",
"for",
"the",
"specified",
"topic",
"and",
"return",
"the",
"first",
"message",
"received",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/tools.go#L90-L151 |
132,097 | honeycombio/honeytail | httime/httime.go | GetTimestamp | func GetTimestamp(m map[string]interface{}, timeFieldName, timeFieldFormat string) time.Time {
var (
ts time.Time
foundFieldName string
timeFoundImproperTypeMsg = "Found time field but type is not string or int"
timeFoundInvalidFormatMsg = "found time field but failed to pars... | go | func GetTimestamp(m map[string]interface{}, timeFieldName, timeFieldFormat string) time.Time {
var (
ts time.Time
foundFieldName string
timeFoundImproperTypeMsg = "Found time field but type is not string or int"
timeFoundInvalidFormatMsg = "found time field but failed to pars... | [
"func",
"GetTimestamp",
"(",
"m",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"timeFieldName",
",",
"timeFieldFormat",
"string",
")",
"time",
".",
"Time",
"{",
"var",
"(",
"ts",
"time",
".",
"Time",
"\n",
"foundFieldName",
"string",
"\n",
"tim... | // GetTimestamp looks through the event map for something that looks like a
// timestamp.
//
// It will guess at the key name or use the specified one if it is not an empty
// string. If unable to parse the timestamp, it will return the current time.
// The time field will be deleted from the map if found. | [
"GetTimestamp",
"looks",
"through",
"the",
"event",
"map",
"for",
"something",
"that",
"looks",
"like",
"a",
"timestamp",
".",
"It",
"will",
"guess",
"at",
"the",
"key",
"name",
"or",
"use",
"the",
"specified",
"one",
"if",
"it",
"is",
"not",
"an",
"empt... | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/httime/httime.go#L114-L176 |
132,098 | honeycombio/honeytail | httime/httime.go | Parse | func Parse(format, timespec string) (time.Time, error) {
return time.ParseInLocation(format, timespec, Location)
} | go | func Parse(format, timespec string) (time.Time, error) {
return time.ParseInLocation(format, timespec, Location)
} | [
"func",
"Parse",
"(",
"format",
",",
"timespec",
"string",
")",
"(",
"time",
".",
"Time",
",",
"error",
")",
"{",
"return",
"time",
".",
"ParseInLocation",
"(",
"format",
",",
"timespec",
",",
"Location",
")",
"\n",
"}"
] | // Parse wraps time.ParseInLocation to use httime's Location from parsers | [
"Parse",
"wraps",
"time",
".",
"ParseInLocation",
"to",
"use",
"httime",
"s",
"Location",
"from",
"parsers"
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/httime/httime.go#L179-L181 |
132,099 | honeycombio/honeytail | httime/httime.go | convertTimeFormat | func convertTimeFormat(layout string) string {
for format, conv := range convertMapping {
layout = strings.Replace(layout, format, conv, -1)
}
return layout
} | go | func convertTimeFormat(layout string) string {
for format, conv := range convertMapping {
layout = strings.Replace(layout, format, conv, -1)
}
return layout
} | [
"func",
"convertTimeFormat",
"(",
"layout",
"string",
")",
"string",
"{",
"for",
"format",
",",
"conv",
":=",
"range",
"convertMapping",
"{",
"layout",
"=",
"strings",
".",
"Replace",
"(",
"layout",
",",
"format",
",",
"conv",
",",
"-",
"1",
")",
"\n",
... | // convertTimeFormat tries to handle C-style time formats alongside Go's
// existing time.Parse behavior. | [
"convertTimeFormat",
"tries",
"to",
"handle",
"C",
"-",
"style",
"time",
"formats",
"alongside",
"Go",
"s",
"existing",
"time",
".",
"Parse",
"behavior",
"."
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/httime/httime.go#L185-L190 |
Subsets and Splits
SQL Console for google/code_x_glue_ct_code_to_text
This query implements a thoughtful three-tier curation strategy to build a balanced safety dataset, categorizing code by destructive operations, safe I/O operations, and pure computational negatives with subsampling—revealing important patterns about how destructive intent manifests in Python code for model safety research.
SQL Console for google/code_x_glue_ct_code_to_text
This query performs meaningful classification of Python code samples into safety-relevant tiers based on destructive operations, I/O patterns, and pure computation, which could be valuable for building safety classifiers or curating training data, though the output itself is a filtered/ranked dataset rather than revealing novel statistical insights.