static void sk_proxy_flush(Socket s) { Proxy_Socket ps = (Proxy_Socket) s; if (ps->state != PROXY_STATE_ACTIVE) { ps->pending_flush = 1; return; } sk_flush(ps->sub_socket); }
static void sk_proxy_flush (Socket s) { ProxySocket *ps = FROMFIELD(s, ProxySocket, sockvt); if (ps->state != PROXY_STATE_ACTIVE) { ps->pending_flush = 1; return; } sk_flush(ps->sub_socket); }
static void sk_proxy_flush (Socket *s) { ProxySocket *ps = container_of(s, ProxySocket, sock); if (ps->state != PROXY_STATE_ACTIVE) { ps->pending_flush = true; return; } sk_flush(ps->sub_socket); }
/* * Call this when proxy negotiation is complete, so that this * socket can begin working normally. */ void proxy_activate(Proxy_Socket p) { void *data; int len; long output_before, output_after; p->state = PROXY_STATE_ACTIVE; /* we want to ignore new receive events until we have sent * all of our buffered receive data. */ sk_set_frozen(p->sub_socket, 1); /* how many bytes of output have we buffered? */ output_before = bufchain_size(&p->pending_oob_output_data) + bufchain_size(&p->pending_output_data); /* and keep track of how many bytes do not get sent. */ output_after = 0; /* send buffered OOB writes */ while (bufchain_size(&p->pending_oob_output_data) > 0) { bufchain_prefix(&p->pending_oob_output_data, &data, &len); output_after += sk_write_oob(p->sub_socket, data, len); bufchain_consume(&p->pending_oob_output_data, len); } /* send buffered normal writes */ while (bufchain_size(&p->pending_output_data) > 0) { bufchain_prefix(&p->pending_output_data, &data, &len); output_after += sk_write(p->sub_socket, data, len); bufchain_consume(&p->pending_output_data, len); } /* if we managed to send any data, let the higher levels know. */ if (output_after < output_before) plug_sent(p->plug, output_after); /* if we were asked to flush the output during * the proxy negotiation process, do so now. */ if (p->pending_flush) sk_flush(p->sub_socket); /* if we have a pending EOF to send, send it */ if (p->pending_eof) sk_write_eof(p->sub_socket); /* if the backend wanted the socket unfrozen, try to unfreeze. * our set_frozen handler will flush buffered receive data before * unfreezing the actual underlying socket. */ if (!p->freeze) sk_set_frozen((Socket)p, 0); }
/* * Called to set up the adb connection. * * Returns an error message, or NULL on success. * * Also places the canonical host name into `realhost'. It must be * freed by the caller. */ static const char *adb_init(void *frontend_handle, void **backend_handle, Config *cfg, char *host, int port, char **realhost, int nodelay, int keepalive) { static const struct plug_function_table fn_table = { adb_log, adb_closing, adb_receive, adb_sent }; SockAddr addr; const char *err; Adb adb; adb = snew(struct adb_backend_data); adb->fn = &fn_table; adb->s = NULL; adb->state = 0; *backend_handle = adb; adb->frontend = frontend_handle; /* * Try to find host. */ { char *buf; buf = dupprintf("Looking up host \"%s\"%s", "localhost", (cfg->addressfamily == ADDRTYPE_IPV4 ? " (IPv4)" : (cfg->addressfamily == ADDRTYPE_IPV6 ? " (IPv6)" : ""))); logevent(adb->frontend, buf); sfree(buf); } addr = name_lookup("localhost", port, realhost, cfg, cfg->addressfamily); if ((err = sk_addr_error(addr)) != NULL) { sk_addr_free(addr); return err; } if (port < 0) port = 5037; /* default adb port */ /* * Open socket. */ adb->s = new_connection(addr, *realhost, port, 0, 1, nodelay, keepalive, (Plug) adb, cfg); if ((err = sk_socket_error(adb->s)) != NULL) return err; if (*cfg->loghost) { char *colon; sfree(*realhost); *realhost = dupstr(cfg->loghost); colon = strrchr(*realhost, ':'); if (colon) { /* * FIXME: if we ever update this aspect of ssh.c for * IPv6 literal management, this should change in line * with it. */ *colon++ = '\0'; } } /* send initial data to adb server */ #define ADB_SHELL_DEFAULT_STR "0012" "host:transport-usb" #define ADB_SHELL_DEFAULT_STR_LEN (sizeof(ADB_SHELL_DEFAULT_STR)-1) #define ADB_SHELL_SERIAL_PREFIX "host:transport:" #define ADB_SHELL_SERIAL_PREFIX_LEN (sizeof(ADB_SHELL_SERIAL_PREFIX)-1) do { size_t len = strlen(host); if (len == 0) { sk_write(adb->s, ADB_SHELL_DEFAULT_STR, ADB_SHELL_DEFAULT_STR_LEN); } else { char sendbuf[512]; #define ADB_SHELL_HOST_MAX_LEN \ (sizeof(sendbuf)-4-ADB_SHELL_SERIAL_PREFIX_LEN-1) if (len > ADB_SHELL_HOST_MAX_LEN) len = ADB_SHELL_HOST_MAX_LEN; sprintf(sendbuf,"%04x" ADB_SHELL_SERIAL_PREFIX, len+ADB_SHELL_SERIAL_PREFIX_LEN); memcpy(sendbuf+4+ADB_SHELL_SERIAL_PREFIX_LEN, host, len); sk_write(adb->s,sendbuf,len+4+ADB_SHELL_SERIAL_PREFIX_LEN); } } while (0); sk_flush(adb->s); adb->state = 1; return NULL; }