7 #define READ_TIMEOUT (250 * 1000)
25 if (
g->data_len ==
g->data_max - 1) {
26 int newsize =
g->data_max * 2;
32 eprintf(
"%s: Failed to reallocate buffer\n",
37 g->data_max = newsize;
39 g->data[
g->data_len++] = ch;
47 g->read_buff[
len] =
'\0';
48 for (
i = 0;
i <
len;
i++) {
49 char cur =
g->read_buff[
i];
52 if (!--
ctx->chksum_nibble) {
55 if (
ctx->sum !=
'#') {
56 eprintf(
"%s: Invalid checksum\n", __func__);
60 if (
g->read_buff[
i + 1] ==
'$' ||
61 (
g->read_buff[
i + 1] ==
'+' &&
g->read_buff[
i + 2] ==
'$')) {
63 g->read_len =
len -
i - 1;
64 memcpy(
g->read_buff,
g->read_buff +
i + 1,
g->read_len);
65 g->read_buff[
g->read_len] =
'\0';
68 eprintf(
"%s: Garbage at end of packet: %s (%s)\n",
69 __func__,
g->read_buff +
i + 1,
g->read_buff +
i + 1);
83 if (cur < 32 || cur > 126) {
84 eprintf(
"%s: Invalid repeat count: %d\n",
88 for (j = cur - 29; j > 0; j--) {
100 eprintf(
"%s: More than one $\n", __func__);
109 ctx->chksum_nibble = 1;
116 eprintf(
"%s: Invalid repeat\n", __func__);
125 if (
g->server_debug && !
g->no_ack) {
126 eprintf(
"[received '%c' (0x%x)]\n", cur,
147 eprintf(
"Initialize libgdbr_t first\n");
151 if (
g->read_len > 0) {
154 g->data[
g->data_len] =
'\0';
155 if (
g->server_debug) {
156 eprintf(
"getpkt (\"%s\"); %s\n",
g->data,
157 g->no_ack ?
"[no ack sent]" :
"[sending ack]");
163 for (
i = 0;
i <
g->num_retries && !
g->isbreaked; vcont ? 0 :
i++) {
165 if (ret == 0 && !vcont) {
173 eprintf(
"%s: read failed\n", __func__);
178 eprintf(
"%s: unpack failed\n", __func__);
182 g->data[
g->data_len] =
'\0';
183 if (
g->server_debug) {
184 eprintf(
"getpkt (\"%s\"); %s\n",
g->data,
185 g->no_ack ?
"[no ack sent]" :
"[sending ack]");
195 eprintf(
"Initialize libgdbr_t first\n");
198 if (
g->server_debug) {
199 g->send_buff[
g->send_len] =
'\0';
200 eprintf(
"putpkt (\"%s\"); %s\n",
g->send_buff,
201 g->no_ack ?
"[noack mode]" :
"[looking for ack]");
214 msg_len = strlen(
msg);
215 if (msg_len >
g->send_max + 5) {
216 eprintf(
"%s: message too long: %s", __func__,
msg);
222 g->send_buff[0] =
'$';
226 if (*
src ==
'#' || *
src ==
'$' || *
src ==
'}') {
228 if (msg_len >
g->send_max + 5) {
229 eprintf(
"%s: message too long: %s", __func__,
msg);
232 g->send_buff[
g->send_len++] =
'}';
233 g->send_buff[
g->send_len++] = *
src++ ^ 0x20;
236 g->send_buff[
g->send_len++] = *
src++;
242 while (
src[run_len] == prev) {
247 g->send_buff[
g->send_len++] = *
src++;
252 if (run_len == 35 || run_len == 36) {
254 }
else if (run_len > 126) {
257 g->send_buff[
g->send_len++] =
'*';
258 g->send_buff[
g->send_len++] = run_len;
259 msg_len -= run_len - 27;
262 g->send_buff[
g->send_len] =
'\0';
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
void * realloc(void *ptr, size_t size)
RZ_API int rz_socket_ready(RzSocket *s, int secs, int usecs)
RZ_API void RZ_API int rz_socket_read(RzSocket *s, ut8 *read, int len)
RZ_API int rz_socket_write(RzSocket *s, void *buf, int len)
int read_packet(libgdbr_t *g, bool vcont)
Function reads data from the established connection.
int send_packet(libgdbr_t *g)
sends a packet sends a packet to the established connection
int pack(libgdbr_t *g, const char *msg)
static bool append(libgdbr_t *g, const char ch)
static int unpack(libgdbr_t *g, struct parse_ctx *ctx, int len)
static struct sockaddr static addrlen static backlog const void msg
uint8_t cmd_checksum(const char *command)