int readData(aeEventLoop *el, int fd, char *data, size_t size){ if(master_fd == -1){ connectToMaster(el); } if(fd == -1){ log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "readData fd ==-1 at line %d in file %s", __LINE__, __FILE__); return -1; } int nread = read(fd, data, size); if(nread == 0){ if(errno != EAGAIN && errno != EINPROGRESS){ log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "connection closed, errno = %d at line %d in file %s",errno, __LINE__, __FILE__); closeFd(fd, el); return -1; } return 0; } else if(nread < 0){ if(errno != EAGAIN && errno != EINPROGRESS ){ log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "readData errno = %d at line %d in file %s",errno, __LINE__, __FILE__); closeFd(fd, el); return -1; } return 0; } else return nread; }
int writeData( aeEventLoop* el,int fd, char *data, int len){ int wr; int all_write = 0; if(master_fd == -1){ connectToMaster(el); } if(fd == -1){ log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "%s , at line %d in file %s", "write fd == -1 error ", __LINE__, __FILE__); return -1; } while(all_write < len){ wr = write(fd, data + all_write, len - all_write); if(wr <= 0){ if(errno == 11 || errno == EINPROGRESS){ continue; } else{ log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "write fd %d all write %d, len %d, errno %d at line %d in file %s", fd, all_write, len, errno, __LINE__, __FILE__); closeFd(fd, el); return -1; } } else{ all_write += wr; if(all_write < wr){ continue; } } } return all_write; }
void CTIServer::connectToServer(const ConnectionConfig &config) { m_config = config; connectToMaster(); }