| 127 | } |
| 128 | |
| 129 | int getJstacks(std::unique_ptr<minifi::io::Socket> socket, std::ostream &out) { |
| 130 | socket->initialize(); |
| 131 | std::vector<uint8_t> data; |
| 132 | uint8_t op = minifi::c2::Operation::DESCRIBE; |
| 133 | minifi::io::BufferStream stream; |
| 134 | stream.write(&op, 1); |
| 135 | stream.write("jstack"); |
| 136 | if (socket->write(const_cast<uint8_t*>(stream.getBuffer()), gsl::narrow<int>(stream.size())) < 0) { |
| 137 | return -1; |
| 138 | } |
| 139 | // read the response |
| 140 | uint8_t resp = 0; |
| 141 | socket->read(&resp, 1); |
| 142 | if (resp == minifi::c2::Operation::DESCRIBE) { |
| 143 | |
| 144 | uint64_t size = 0; |
| 145 | socket->read(size); |
| 146 | |
| 147 | for (int i = 0; i < size; i++) { |
| 148 | std::string name; |
| 149 | uint64_t lines; |
| 150 | socket->read(name); |
| 151 | socket->read(lines); |
| 152 | for (int j = 0; j < lines; j++) { |
| 153 | std::string line; |
| 154 | socket->read(line); |
| 155 | out << name << " -- " << line << std::endl; |
| 156 | } |
| 157 | |
| 158 | } |
| 159 | } |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Prints the connection size for the provided connection. |