| 43 | } |
| 44 | |
| 45 | bool beanstalk::beanstalk_open(void) |
| 46 | { |
| 47 | if (conn_.opened()) { |
| 48 | return true; |
| 49 | } |
| 50 | if (!conn_.open(addr_, timeout_, 0)) { |
| 51 | logger_error("connect server: %s error: %s", |
| 52 | addr_, last_serror()); |
| 53 | errbuf_.format("connect"); |
| 54 | return false; |
| 55 | } |
| 56 | if (tube_used_ && !beanstalk_use()) { |
| 57 | logger_error("use %s error: %s", tube_used_, last_serror()); |
| 58 | conn_.close(); |
| 59 | return false; |
| 60 | } |
| 61 | |
| 62 | if (tubes_watched_.empty()) { |
| 63 | return true; |
| 64 | } |
| 65 | |
| 66 | std::vector<char*>::iterator it = tubes_watched_.begin(); |
| 67 | for (; it != tubes_watched_.end(); ++it) { |
| 68 | if (!beanstalk_watch(*it)) { |
| 69 | logger_error("watch %s failed", *it); |
| 70 | conn_.close(); |
| 71 | return false; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | return true; |
| 76 | } |
| 77 | |
| 78 | bool beanstalk::beanstalk_use(void) |
| 79 | { |