func getClientSubscriberID(cl *data.QueueClient) bool { sClData := string(cl.DataIn) cUuid := uuid.Parse(sClData) if cUuid != nil { cl.SubscriberId = cUuid return true } return false }
func processClientData(cl *data.QueueClient) error { if !getClientSubscriberID(cl) { if string(cl.DataIn) == "OK" { cl.RecieveConfirmation = true } else { err := QueueListenerError("Unexpected data received from client : " + string(cl.DataIn)) return err } } return nil }
func fromClient(context *data.Context, q *data.MessageQueue, cl *data.QueueClient, wg *sync.WaitGroup) { defer wg.Done() for { select { case <-cl.Quit: break default: cl.Conn.SetReadDeadline(time.Now().Add(context.IdleTimeout)) piece := make([]byte, 1) clientdata := []byte{} var err error for { read, err := cl.Conn.Read(piece) // Extend the read time out to allow time for the next piece to arrive cl.Conn.SetReadDeadline(time.Now().Add(context.IdleTimeout)) if err != nil { switch err.(type) { case *net.OpError: // Read operation timing out, most likely no more data if read > 0 { clientdata = append(clientdata, piece...) break } } } else { if read > 0 { clientdata = append(clientdata, piece...) } } if read == 0 { break } } if err != nil { if err.Error() == "EOF" { cl.DataIn = clientdata err := processClientData(cl) if err != nil { log.Printf("Error processing the queue client data : %v\n", err) } } } } } }