Example #1
0
func (clnt *Clnt) send() {
	buf := make([]byte, 8*vt.Maxblock)
	pos := 0

	for {
		select {
		case <-clnt.done:
			return

		case req := <-clnt.reqout:
		again:
			nreqs := 0
			for req != nil {
				req.Tc.Tag = req.tag
				n := vt.Pack(buf[pos:], &req.Tc)
				if n < 0 {
					break
				}

				if clnt.Debuglevel > 0 {
					clnt.logFcall(&req.Rc)
					if clnt.Debuglevel&DbgPrintPackets != 0 {
						log.Println("{-{", clnt.Id, fmt.Sprintf("%x", req.Tc.Pkt))
					}

					if clnt.Debuglevel&DbgPrintCalls != 0 {
						log.Println("{{{", clnt.Id, req.Tc.String())
					}
				}

				pos += n
				nreqs++
				// req is freed in recv() if no Done channel was registered, or by the code calling <-Done.
				//clnt.ReqFree(req)
				select {
				default:
					req = nil

				case req = <-clnt.reqout:
				}
			}

			nwrites := 0
			for b := buf[0:pos]; len(b) > 0; {
				n, err := clnt.conn.Write(b)
				if err != nil {
					clnt.Lock()
					clnt.err = &vt.Error{err.Error()}
					clnt.Unlock()

					/* just close the socket, will get signal on conn.done */
					log.Println("error while writing")
					clnt.conn.Close()
					break
				}
				nwrites++
				b = b[n:]
			}

			clnt.Lock()
			clnt.rsz += uint64(pos)
			clnt.npend -= nreqs
			clnt.nwrites += nwrites
			clnt.Unlock()
			pos = 0
			if req != nil {
				goto again
			}
		}
	}
}
Example #2
0
func (conn *Conn) send() {
	buf := make([]byte, 8*vt.Maxblock)
	pos := 0

	for {
		select {
		case <-conn.done:
			return

		case req := <-conn.reqout:
		again:
			nreqs := 0
			for req != nil {
				req.Rc.Tag = req.Tc.Tag
				n := vt.Pack(buf[pos:], req.Rc)
				if n < 0 {
					break
				}

				if conn.Debuglevel > 0 {
					conn.logFcall(req.Rc)
					if conn.Debuglevel&DbgPrintPackets != 0 {
						log.Println("<-<", conn.Id, fmt.Sprintf("%x", req.Rc.Pkt))
					}

					if conn.Debuglevel&DbgPrintCalls != 0 {
						log.Println("<<<", conn.Id, req.Rc.String())
					}
				}

				pos += n
				nreqs++
				conn.Srv.ReqFree(req)
				select {
				default:
					req = nil
				case req = <-conn.reqout:
				}
			}

			nwrites := 0
			for b := buf[0:pos]; len(b) > 0; {
				n, err := conn.conn.Write(b)
				if err != nil {
					/* just close the socket, will get signal on conn.done */
					log.Println("error while writing")
					conn.conn.Close()
					break
				}
				nwrites++
				b = b[n:]
			}

			conn.Lock()
			conn.rsz += uint64(pos)
			conn.npend -= nreqs
			conn.nwrites += nwrites
			conn.Unlock()
			pos = 0
			if req != nil {
				goto again
			}
		}
	}
}