Every line of 'golang select channel' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.
434 func (s *Dma) chooseChannel() (c *dma_channel) { 435 // Round robin among channels. 436 var i0, i1 uint32 437 for { 438 i0 = atomic.LoadUint32(&s.channel_index) 439 i1 = i0 + 1 440 if i1 >= uint32(len(s.Channels)) { 441 i1 = 0 442 } 443 if atomic.CompareAndSwapUint32(&s.channel_index, i0, i1) { 444 break 445 } 446 } 447 c = &s.Channels[i1] 448 return 449 }
160 func (n *MenuNode) Channel() chan struct{} { 161 switch n.item.(type) { 162 case *systray.MenuItem: 163 return n.item.(*systray.MenuItem).ClickedCh 164 case *mockItem: 165 return n.item.(*mockItem).ClickedCh() 166 default: 167 return nil 168 } 169 }
182 func handleChannelSelect(p packet.Packet, pos *int, conn *loginConn.Connection) { 183 selectedWorld := p.ReadByte(pos) // world 184 p.ReadByte(pos) // Channel 185 186 if uint32(selectedWorld) != conn.GetWorldID() { 187 fmt.Println(conn, "is channel selecting from a world they did not select, sending zero characters") 188 pac := packet.NewPacket() 189 pac.WriteByte(constants.LOGIN_CHARACTER_DATA) 190 pac.WriteByte(0) // ? 191 pac.WriteByte(0) // Character count 192 conn.Write(pac) 193 } else { 194 pac := packet.NewPacket() 195 pac.WriteByte(constants.LOGIN_CHARACTER_DATA) 196 pac.WriteByte(0) // ? 197 198 var charCount byte 199 200 err := connection.Db.QueryRow("SELECT count(*) name FROM characters WHERE userID=? and worldID=?", conn.GetUserID(), selectedWorld). 201 Scan(&charCount) 202 203 if err != nil { 204 panic(err.Error()) 205 } 206 207 pac.WriteByte(charCount) // Character count 208 // Add characters 209 conn.Write(pac) 210 } 211 }
561 func tryChanSelect(recvbuf unsafe.Pointer, states []chanSelectState) (uintptr, bool) { 562 // See whether we can receive from one of the channels. 563 for i, state := range states { 564 if state.value == nil { 565 // A receive operation. 566 if rx, ok := state.ch.tryRecv(recvbuf); rx { 567 chanDebug(state.ch) 568 return uintptr(i), ok 569 } 570 } else { 571 // A send operation: state.value is not nil. 572 if state.ch.trySend(state.value) { 573 chanDebug(state.ch) 574 return uintptr(i), true 575 } 576 } 577 } 578 579 return ^uintptr(0), false 580 }
87 func (c Channel) Channel() uint8 { 88 return uint8(c) 89 }
520 func cgoOnDataChannel(p int, o unsafe.Pointer) { 521 INFO.Println("fired OnDataChannel: ", p, o) 522 pc := PCMap.Get(p).(*PeerConnection) 523 dc := NewDataChannel(o) 524 if nil != pc.OnDataChannel { 525 pc.OnDataChannel(dc) 526 } 527 }
130 func channelReceive(L *LState) int { 131 rch := checkChannel(L, 1) 132 v, ok := rch.Recv() 133 if ok { 134 L.Push(LTrue) 135 L.Push(v.Interface().(LValue)) 136 } else { 137 L.Push(LFalse) 138 L.Push(LNil) 139 } 140 return 2 141 }
104 func (c *EndpointsConfig) Channel(source string) chan EndpointsUpdate { 105 ch := c.mux.Channel(source) 106 endpointsCh := make(chan EndpointsUpdate) 107 go func() { 108 for update := range endpointsCh { 109 ch <- update 110 } 111 }() 112 return endpointsCh 113 }
62 func (c *Controller) UpdateChannel(jack string, ch Channel, v float64) { 63 if ch.Reverse { 64 v = 100 - v 65 } 66 log.Println("lighting-subsystem: Setting PWM value:", v, " at channel:", ch.Pin) 67 pv := make(map[int]float64) 68 pv[ch.Pin] = v 69 if err := c.jacks.Control(jack, pv); err != nil { 70 log.Println("ERROR: lighting-subsystem: Failed to set pwm value. Error:", err) 71 } 72 }
162 func WaitForAny(channels []StopChan) (int, error) { 163 if len(channels) < 1 { 164 return -1, nil 165 } 166 // Use reflect package to wait for any of the given channels 167 var cases []reflect.SelectCase 168 for _, ch := range channels { 169 if ch != nil { 170 refCase := reflect.SelectCase{Dir: reflect.SelectRecv, Chan: reflect.ValueOf(ch)} 171 cases = append(cases, refCase) 172 } 173 } 174 choice, result, _ := reflect.Select(cases) 175 channels[choice] = nil // Already received 176 if err, ok := result.Interface().(error); ok { 177 return choice, err 178 } else { 179 return choice, nil 180 } 181 }