Read a empty data means connection error

This commit is contained in:
mikespook 2012-05-24 21:17:06 +08:00
parent 0d6d1e114f
commit a8f7c8ab9d
3 changed files with 6 additions and 5 deletions

View File

@ -82,7 +82,7 @@ func (client *Client) inLoop() {
for {
rel, err := client.read()
if err != nil {
if err == common.ErrEmptyReading {
if err == common.ErrConnection {
client.Close()
break
}
@ -123,7 +123,7 @@ func (client *Client) read() (data []byte, err error) {
if n, err = client.conn.Read(buf); err != nil {
if err == io.EOF && n == 0 {
if data == nil {
err = common.ErrEmptyReading
err = common.ErrConnection
return
}
break

View File

@ -22,7 +22,7 @@ var (
ErrOutOfCap = errors.New("Out of the capability.")
ErrNotConn = errors.New("Did not connect to job server.")
ErrFuncNotFound = errors.New("The function was not found.")
ErrEmptyReading = errors.New("Empty reading.")
ErrConnection = errors.New("Connection error.")
)
func DisablePanic() {recover()}

View File

@ -61,7 +61,8 @@ func (a *agent) inLoop() {
}
rel, err := a.read()
if err != nil {
if err == common.ErrEmptyReading {
if err == common.ErrConnection {
// TODO: reconnection
break
}
a.worker.err(err)
@ -102,7 +103,7 @@ func (a *agent) read() (data []byte, err error) {
if n, err = a.conn.Read(buf); err != nil {
if err == io.EOF && n == 0 {
if data == nil {
err = common.ErrEmptyReading
err = common.ErrConnection
return
}
break