mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-03 19:56:39 +00:00 
			
		
		
		
	Merge pull request #428 from Arceliar/readerror
Conn.Read don't return useless errors
This commit is contained in:
		@@ -191,6 +191,7 @@ func (c *Conn) Read(b []byte) (int, error) {
 | 
				
			|||||||
			return 0, errors.New("search failed")
 | 
								return 0, errors.New("search failed")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						for {
 | 
				
			||||||
		// Wait for some traffic to come through from the session
 | 
							// Wait for some traffic to come through from the session
 | 
				
			||||||
		select {
 | 
							select {
 | 
				
			||||||
		case <-timer.C:
 | 
							case <-timer.C:
 | 
				
			||||||
@@ -216,7 +217,7 @@ func (c *Conn) Read(b []byte) (int, error) {
 | 
				
			|||||||
				// Check if we were unable to decrypt the packet for some reason and
 | 
									// Check if we were unable to decrypt the packet for some reason and
 | 
				
			||||||
				// return an error if we couldn't
 | 
									// return an error if we couldn't
 | 
				
			||||||
				if !isOK {
 | 
									if !isOK {
 | 
				
			||||||
				err = errors.New("packet dropped due to decryption failure")
 | 
										err = ConnError{errors.New("packet dropped due to decryption failure"), false, true, 0}
 | 
				
			||||||
					return
 | 
										return
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				// Return the newly decrypted buffer back to the slice we were given
 | 
									// Return the newly decrypted buffer back to the slice we were given
 | 
				
			||||||
@@ -239,6 +240,9 @@ func (c *Conn) Read(b []byte) (int, error) {
 | 
				
			|||||||
			<-done // Wait for the worker to finish, failing this can cause memory errors (util.[Get||Put]Bytes stuff)
 | 
								<-done // Wait for the worker to finish, failing this can cause memory errors (util.[Get||Put]Bytes stuff)
 | 
				
			||||||
			// Something went wrong in the session worker so abort
 | 
								// Something went wrong in the session worker so abort
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
 | 
									if ce, ok := err.(*ConnError); ok && ce.Temporary() {
 | 
				
			||||||
 | 
										continue
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
				return 0, err
 | 
									return 0, err
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			// If we've reached this point then everything went to plan, return the
 | 
								// If we've reached this point then everything went to plan, return the
 | 
				
			||||||
@@ -246,6 +250,7 @@ func (c *Conn) Read(b []byte) (int, error) {
 | 
				
			|||||||
			return len(b), nil
 | 
								return len(b), nil
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (c *Conn) Write(b []byte) (bytesWritten int, err error) {
 | 
					func (c *Conn) Write(b []byte) (bytesWritten int, err error) {
 | 
				
			||||||
	c.mutex.RLock()
 | 
						c.mutex.RLock()
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user