123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- package door
- import (
- "fmt"
- "log"
- "strings"
- "syscall"
- )
- func Writer(d *Door) {
- var handle syscall.Handle = syscall.Handle(d.WRITEFD) // Config.Comm_handle)
- // handle syscall.Handle, writerChannel *chan string
- log.Println("Writer")
- defer d.wg.Done()
- var Closed bool = false
- for output := range d.writerChannel {
- // for {
- /*
- select {
- case <-d.closeChannel:
- close(d.writerChannel)
- log.Println("~Writer")
- return
- default:
- }
- */
- // select {
- /*
- case <-d.closeChannel:
- close(d.writerChannel)
- log.Println("~Writer")
- return
- */
- /*
- case output, ok := <-d.writerChannel:
- if !ok {
- log.Println("closeChannel")
- d.writerMutex.Lock()
- if !d.WriterClosed {
- d.WriterClosed = true
- }
- d.writerMutex.Unlock()
- log.Println("~Writer")
- return
- } else {
- */
- if output == "" {
- Closed = true
- continue
- }
- if Closed {
- log.Println("Ignoring write output.")
- continue
- }
- if strings.HasSuffix(output, RestorePos) {
- output += Color(d.LastColor)
- } else {
- d.UpdateLastColor(output, &d.LastColor)
- }
- var l uint32 = uint32(len(output))
- var buffer []byte = []byte(output)
- WSA_Buffer := syscall.WSABuf{Len: uint32(l), Buf: &buffer[0]}
- var UitnZero_1 uint32 = uint32(0)
- var DataWrite uint32 = uint32(0)
- var err error
- err = syscall.WSASend(handle, &WSA_Buffer, 1, &DataWrite, UitnZero_1, nil, nil)
- if DEBUG_OUTPUT {
- if err != nil {
- fmt.Printf("write: %d bytes, error: %#v\n", DataWrite, err)
- } else {
- log.Printf("write %d bytes\n", DataWrite)
- }
- }
- if (err != nil) || (l != DataWrite) {
- log.Println("CloseChannel")
- Closed = true
- d.writerMutex.Lock()
- if !d.WriterClosed {
- d.WriterClosed = true
- }
- d.writerMutex.Unlock()
- /*
- if !d.Disconnect() {
- atomic.StoreInt32(&d.Disconnected, 1)
- close(d.writerChannel)
- }
- log.Println("~Writer")
- return
- */
- // }
- // }
- }
- }
- log.Println("closeChannel")
- d.writerMutex.Lock()
- if !d.WriterClosed {
- d.WriterClosed = true
- }
- d.writerMutex.Unlock()
- log.Println("~Writer")
- // return
- /*
- for output := range *writerChannel {
- l := uint32(len(output))
- buffer := []byte(output)
- WSA_Buffer := syscall.WSABuf{Len: uint32(l), Buf: &buffer[0]}
- UitnZero_1 := uint32(0)
- DataWrite := uint32(0)
- err := syscall.WSASend(handle, &WSA_Buffer, 1, &DataWrite, UitnZero_1, nil, nil)
- if err != nil {
- fmt.Printf("write: %d bytes, error: %#v\n", DataWrite, err)
- }
- if (err != nil) || (l != DataWrite) {
- close(*writerChannel)
- break
- }
- }
- */
- }
|