ing
This commit is contained in:
		
							parent
							
								
									10cadfc5b5
								
							
						
					
					
						commit
						f22f37a6dc
					
				| @ -10,7 +10,7 @@ import ( | |||||||
| 
 | 
 | ||||||
| // Codec creates a CodecRequest to process each request. | // Codec creates a CodecRequest to process each request. | ||||||
| type Codec interface { | type Codec interface { | ||||||
| 	NewRequest(rc io.Reader) CodecRequest | 	NewRequest(rc io.Reader) (CodecRequest, error) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // CodecRequest decodes a request and encodes a response using a specific | // CodecRequest decodes a request and encodes a response using a specific | ||||||
|  | |||||||
| @ -72,7 +72,7 @@ type Codec struct { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // NewRequest returns a CodecRequest. | // NewRequest returns a CodecRequest. | ||||||
| func (c *Codec) NewRequest(r io.Reader) protocol.CodecRequest { | func (c *Codec) NewRequest(r io.Reader) (protocol.CodecRequest, error) { | ||||||
| 	return newCodecRequest(r, c.encSel.Select(r)) | 	return newCodecRequest(r, c.encSel.Select(r)) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -81,12 +81,13 @@ func (c *Codec) NewRequest(r io.Reader) protocol.CodecRequest { | |||||||
| // ---------------------------------------------------------------------------- | // ---------------------------------------------------------------------------- | ||||||
| 
 | 
 | ||||||
| // newCodecRequest returns a new CodecRequest. | // newCodecRequest returns a new CodecRequest. | ||||||
| func newCodecRequest(r io.Reader, encoder encode.Encoder) protocol.CodecRequest { | func newCodecRequest(r io.Reader, encoder encode.Encoder) (protocol.CodecRequest, error) { | ||||||
| 	// Decode the request body and check if RPC method is valid. | 	// Decode the request body and check if RPC method is valid. | ||||||
| 	req := new(serverRequest) | 	req := new(serverRequest) | ||||||
| 	err := json.NewDecoder(r).Decode(req) | 	err := json.NewDecoder(r).Decode(req) | ||||||
| 	if err == io.ErrUnexpectedEOF || err == io.EOF { | 	if err == io.ErrUnexpectedEOF || err == io.EOF { | ||||||
| 		log.Printf("NewRequest err: %v", err) | 		log.Printf("NewRequest err: %v", err) | ||||||
|  | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		err = &Error{ | 		err = &Error{ | ||||||
| @ -103,7 +104,7 @@ func newCodecRequest(r io.Reader, encoder encode.Encoder) protocol.CodecRequest | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return &CodecRequest{request: req, err: err, encoder: encoder} | 	return &CodecRequest{request: req, err: err, encoder: encoder}, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // CodecRequest decodes and encodes a single request. | // CodecRequest decodes and encodes a single request. | ||||||
|  | |||||||
| @ -101,7 +101,10 @@ func (rr *rpcRegistry) Invoke(contentType string, r io.Reader, w io.Writer, befo | |||||||
| 
 | 
 | ||||||
| 	log.Print("codec.NewRequest") | 	log.Print("codec.NewRequest") | ||||||
| 	// Create a new codec request. | 	// Create a new codec request. | ||||||
| 	codecReq := codec.NewRequest(r) | 	codecReq, errNew := codec.NewRequest(r) | ||||||
|  | 	if nil != errNew { | ||||||
|  | 		return errNew | ||||||
|  | 	} | ||||||
| 	// Get service method to be called. | 	// Get service method to be called. | ||||||
| 	log.Printf("codecReq.Method: %v", codecReq) | 	log.Printf("codecReq.Method: %v", codecReq) | ||||||
| 	method, errMethod := codecReq.Method() | 	method, errMethod := codecReq.Method() | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user