gboolean afsocket_dd_start_connect(AFSocketDestDriver *self) { int sock, rc; gchar buf1[MAX_SOCKADDR_STRING], buf2[MAX_SOCKADDR_STRING]; if (!afsocket_open_socket(self->bind_addr, !!(self->flags & AFSOCKET_STREAM), &sock)) { return FALSE; } if (self->setup_socket && !self->setup_socket(self, sock)) { close(sock); return FALSE; } rc = g_connect(sock, self->dest_addr); if (rc == G_IO_STATUS_NORMAL) { self->fd = sock; afsocket_dd_connected(self); } else if (rc == G_IO_STATUS_ERROR && errno == EINPROGRESS) { GSource *source; /* we must wait until connect succeeds */ self->fd = sock; source = g_connect_source_new(sock); /* a reference is added on behalf of the source, it will be unrefed when * the source is destroyed */ log_pipe_ref(&self->super.super); g_source_set_callback(source, (GSourceFunc) afsocket_dd_connected, self, (GDestroyNotify) log_pipe_unref); self->source_id = g_source_attach(source, NULL); g_source_unref(source); } else { /* error establishing connection */ msg_error("Connection failed", evt_tag_int("fd", sock), evt_tag_str("server", g_sockaddr_format(self->dest_addr, buf2, sizeof(buf2), GSA_FULL)), evt_tag_str("local", g_sockaddr_format(self->bind_addr, buf1, sizeof(buf1), GSA_FULL)), evt_tag_errno(EVT_TAG_OSERROR, errno), NULL); close(sock); return FALSE; } return TRUE; }
static gboolean afsocket_dd_start_connect(AFSocketDestDriver *self) { int sock, rc; gchar buf1[MAX_SOCKADDR_STRING], buf2[MAX_SOCKADDR_STRING]; main_loop_assert_main_thread(); if (!afsocket_open_socket(self->bind_addr, !!(self->flags & AFSOCKET_STREAM), &sock)) { return FALSE; } if (self->setup_socket && !self->setup_socket(self, sock)) { close(sock); return FALSE; } g_assert(self->dest_addr); rc = g_connect(sock, self->dest_addr); if (rc == G_IO_STATUS_NORMAL) { self->fd = sock; afsocket_dd_connected(self); } else if (rc == G_IO_STATUS_ERROR && errno == EINPROGRESS) { /* we must wait until connect succeeds */ self->fd = sock; afsocket_dd_start_watches(self); } else { /* error establishing connection */ msg_error("Connection failed", evt_tag_int("fd", sock), evt_tag_str("server", g_sockaddr_format(self->dest_addr, buf2, sizeof(buf2), GSA_FULL)), evt_tag_str("local", g_sockaddr_format(self->bind_addr, buf1, sizeof(buf1), GSA_FULL)), evt_tag_errno(EVT_TAG_OSERROR, errno), NULL); close(sock); return FALSE; } return TRUE; }
void g_parse (Graph *gg, FILE *stream) { int status, cost; char src[100], dst[100]; src[99] = '\0'; dst[99] = '\0'; for (;;) { status = fscanf (stream, " %99s %99s %d", src, dst, &cost); if (EOF == status) break; if (3 != status) errx (EXIT_FAILURE, __FILE__": %s: expected two strings and an integer", __func__); g_connect (gg, src, dst, cost); } }
static gboolean slng_send_cmd(gchar *cmd) { GSockAddr *saddr = NULL; if (control_socket == -1) { saddr = g_sockaddr_unix_new(control_name); control_socket = socket(PF_UNIX, SOCK_STREAM, 0); if (control_socket == -1) { fprintf(stderr, "Error opening control socket, socket='%s', error='%s'\n", control_name, strerror(errno)); goto error; } if (g_connect(control_socket, saddr) != G_IO_STATUS_NORMAL) { fprintf(stderr, "Error connecting control socket, socket='%s', error='%s'\n", control_name, strerror(errno)); close(control_socket); control_socket = -1; goto error; } } if (write(control_socket, cmd, strlen(cmd)) < 0) { fprintf(stderr, "Error sending command on control sokcet, socket='%s', cmd='%s', error='%s'\n", control_name, cmd, strerror(errno)); goto error; } return TRUE; error: if (saddr) g_sockaddr_unref(saddr); return FALSE; }
Engine * GpBXEngine(char *name, int landscape, int dpi, char *displayName) { p_scr *s = g_connect(displayName); int topWidth = DefaultTopWidth(dpi); int topHeight = DefaultTopHeight(dpi); GpTransform toPixels; int x, y, width, height, hints; XEngine *xeng; if (!s) return 0; SetXTransform(&toPixels, landscape, dpi); width = (int)toPixels.window.xmax; height = (int)toPixels.window.ymin; x = (width-topWidth)/2; if (landscape) y = (height-topHeight)/2; else y = (width-topHeight)/2; if (y<0) y = 0; if (x<0) x = 0; xeng = GxEngine(s, name, &toPixels, -x,-y,0,0, sizeof(XEngine)); xeng->wtop = topWidth; xeng->htop = topHeight; /* possibly want optional P_RGBMODEL as well */ hints = (gist_private_map?P_PRIVMAP:0) | (gist_input_hint?0:P_NOKEY) | (gist_rgb_hint?P_RGBMODEL:0); xeng->win = xeng->w = gx_parent? p_subwindow(s, topWidth, topHeight, gx_parent, gx_xloc, gx_yloc, P_BG, hints, xeng) : p_window(s, topWidth, topHeight, name, P_BG, hints, xeng); gx_parent = 0; if (!xeng->win) { GpDelEngine(&xeng->e); return 0; } return &xeng->e; }
int stomp_connect(stomp_connection **connection_ref, char *hostname, int port) { stomp_connection *conn; conn = g_new0(stomp_connection, 1); conn->socket = socket(AF_INET, SOCK_STREAM, 0); if (conn->socket == -1) { msg_error("Failed to create socket!", NULL); return FALSE; } if (!resolve_hostname_to_sockaddr(&conn->remote_sa, AF_INET, hostname)) { msg_error("Failed to resolve hostname in stomp driver", evt_tag_str("hostname", hostname), NULL); return FALSE; } g_sockaddr_set_port(conn->remote_sa, port); if (!g_connect(conn->socket, conn->remote_sa)) { msg_error("Stomp connection failed", evt_tag_str("host", hostname), NULL); _stomp_connection_free(conn); return FALSE; } (*connection_ref) = conn; return TRUE; };