// this servers "procedure"
this servers "procedure"
// this servers " procedure "
func (twoway *Bilateral) rpcProcedure() {
	twoway.rpcShutdown = make(chan bool)
	defer close(twoway.rpcShutdown)
loop:
	for {
		select {
		case request := <-twoway.rpcServerCallChannel:
			go func() {
				buffer := bytes.NewBuffer(request.request)
				dec := gob.NewDecoder(buffer)
				var id uint32
				err := dec.Decode(&id)
				if nil != err {
					log.Errorf("id decode error: %v", err)
				}
				var method string
				err = dec.Decode(&method)
				if nil != err {
					log.Errorf("method decode error: %v", err)
				}
				log.Debugf("RPC %q request: %d %s", request.from, id, method)
				responseBuffer := new(bytes.Buffer)
				enc := gob.NewEncoder(responseBuffer)
				err = enc.Encode(id)
				if err != nil {
					log.Errorf("id encode error: %v", err)
				}
				err = enc.Encode(method)
				if err != nil {
					log.Errorf("method encode error: %v", err)
				}
				err = twoway.server.Call(method, buffer, responseBuffer, request.from)
				if err != nil {
					log.Errorf("reply error encode error: %v", err)
				}
				if request.wantReply {
					log.Debugf("RPC %q reply: %d %x", request.from, id, responseBuffer)
					twoway.rpcServerBackChannel <- rpcServerBackData{
						socket:   request.socket,
						to:       request.from,
						response: responseBuffer.Bytes(),
					}
				}
			}()
		case <-twoway.shutdownAll:
			break loop
		}
	}
	log.Info("RPC exit")
}
func ( twoway * Bilateral ) rpcProcedure ( ) { twoway . rpcShutdown = make ( chan bool ) defer close ( twoway . rpcShutdown ) loop : for { select { case request := <- twoway . rpcServerCallChannel : go func ( ) { buffer := bytes . NewBuffer ( request . request ) dec := gob . NewDecoder ( buffer ) var id uint32 err := dec . Decode ( & id ) if nil != err { log . Errorf ( " " , err ) } var method string err = dec . Decode ( & method ) if nil != err { log . Errorf ( " " , err ) } log . Debugf ( " " , request . from , id , method ) responseBuffer := new ( bytes . Buffer ) enc := gob . NewEncoder ( responseBuffer ) err = enc . Encode ( id ) if err != nil { log . Errorf ( " " , err ) } err = enc . Encode ( method ) if err != nil { log . Errorf ( " " , err ) } err = twoway . server . Call ( method , buffer , responseBuffer , request . from ) if err != nil { log . Errorf ( " " , err ) } if request . wantReply { log . Debugf ( " " , request . from , id , responseBuffer ) twoway . rpcServerBackChannel <- rpcServerBackData { socket : request . socket , to : request . from , response : responseBuffer . Bytes ( ) , } } } ( ) case <- twoway . shutdownAll : break loop } } log . Info ( " " ) }
this servers "procedure"
this servers " procedure "
// received a request for process