func EmulateIcecast(connection net.Conn) {
	var incomingMessage []byte = make([]byte, 0, 4096)
	var temporaryBuffer []byte = make([]byte, 256)

	for !bytes.Contains(incomingMessage, []byte{13, 10, 13, 10}) {
		length, err := connection.Read(temporaryBuffer)
		if err != nil {
			break
		}
		incomingMessage = append(incomingMessage, temporaryBuffer[:length]...)
	}

	if !icecastHandleHeaders(connection, string(incomingMessage)) {
		return
	}

	reader := bufio.NewReader(connection)
	channelID := SocketClients[connection].channel
	var err error

	for {
		if _, err = reader.Read(ActiveChannels[channelID].temporaryInputBuffer); err != nil {
			delete(SocketClients, connection)
			connection.Close()
			return
		}

		ActiveChannels[channelID].mainBuffer = append(ActiveChannels[channelID].mainBuffer[4096:],
			ActiveChannels[channelID].temporaryInputBuffer[:]...)
		time.Sleep(ActiveChannels[channelID].bitrateInterval)
	}
}
// EmulateIcecast handles most of the socket connection,
// firstly it parses the HTTP headers and collects the most
// important data, then proceeds to listen to data stream
// provided by the client that is being appended into the
// mainBuffer of channel described in PUT request.
EmulateIcecast handles most of the socket connection,
firstly it parses the HTTP headers and collects the most
important data, then proceeds to listen to data stream
provided by the client that is being appended into the
mainBuffer of channel described in PUT request.
// EmulateIcecast handles most of the socket connection // firstly it parses the HTTP headers and collects the most // important data then proceeds to listen to data stream // provided by the client that is being appended into the // mainBuffer of channel described in PUT request .
func EmulateIcecast(connection net.Conn) {
	var incomingMessage []byte = make([]byte, 0, 4096)
	var temporaryBuffer []byte = make([]byte, 256)
	for !bytes.Contains(incomingMessage, []byte{13, 10, 13, 10}) {
		length, err := connection.Read(temporaryBuffer)
		if err != nil {
			break
		}
		incomingMessage = append(incomingMessage, temporaryBuffer[:length]...)
	}
	if !icecastHandleHeaders(connection, string(incomingMessage)) {
		return
	}
	reader := bufio.NewReader(connection)
	channelID := SocketClients[connection].channel
	var err error
	for {
		if _, err = reader.Read(ActiveChannels[channelID].temporaryInputBuffer); err != nil {
			delete(SocketClients, connection)
			connection.Close()
			return
		}
		ActiveChannels[channelID].mainBuffer = append(ActiveChannels[channelID].mainBuffer[4096:],
			ActiveChannels[channelID].temporaryInputBuffer[:]...)
		time.Sleep(ActiveChannels[channelID].bitrateInterval)
	}
}
func EmulateIcecast ( connection net . Conn ) { var incomingMessage [ ] byte = make ( [ ] byte , 0 , 4096 ) var temporaryBuffer [ ] byte = make ( [ ] byte , 256 ) for ! bytes . Contains ( incomingMessage , [ ] byte { 13 , 10 , 13 , 10 } ) { length , err := connection . Read ( temporaryBuffer ) if err != nil { break } incomingMessage = append ( incomingMessage , temporaryBuffer [ : length ] ... ) } if ! icecastHandleHeaders ( connection , string ( incomingMessage ) ) { return } reader := bufio . NewReader ( connection ) channelID := SocketClients [ connection ] . channel var err error for { if _ , err = reader . Read ( ActiveChannels [ channelID ] . temporaryInputBuffer ) ; err != nil { delete ( SocketClients , connection ) connection . Close ( ) return } ActiveChannels [ channelID ] . mainBuffer = append ( ActiveChannels [ channelID ] . mainBuffer [ 4096 : ] , ActiveChannels [ channelID ] . temporaryInputBuffer [ : ] ... ) time . Sleep ( ActiveChannels [ channelID ] . bitrateInterval ) } }
EmulateIcecast handles most of the socket connection,
firstly it parses the HTTP headers and collects the most
important data, then proceeds to listen to data stream
provided by the client that is being appended into the
mainBuffer of channel described in PUT request.
EmulateIcecast handles most of the socket connection firstly it parses the HTTP headers and collects the most important data then proceeds to listen to data stream provided by the client that is being appended into the mainBuffer of channel described in PUT request .