/* * Application entry point. */ int main(int argc, char **argv) { // Skip first parameter (program name). argv++; // Open input file. STREAM sin; if (argv) { if (!(sin = sopenRead(*argv))) error("Error: Input file \"%s\" can not be open.", *argv) argv++; } else sin = STREAM_STDIN; // Open output file. STREAM sout; if (argv) { if (!(sout = sopenWrite(*argv))) error("Error: Output file \"%s\" can not be open.", *argv); } else sout = STREAM_STDOUT; // Proceed with filtering. filterComment(sin, sout); sclose(sin); sclose(sout); return 0; }
char *Curl_if2ip(const char *interface, char *buf, int buf_size) { int dummy; char *ip=NULL; if(!interface) return NULL; dummy = socket(AF_INET, SOCK_STREAM, 0); if (SYS_ERROR == dummy) { return NULL; } else { struct ifreq req; size_t len = strlen(interface); memset(&req, 0, sizeof(req)); if(len >= sizeof(req.ifr_name)) return NULL; /* this can't be a fine interface name */ memcpy(req.ifr_name, interface, len+1); req.ifr_addr.sa_family = AF_INET; #ifdef IOCTL_3_ARGS if (SYS_ERROR == ioctl(dummy, SIOCGIFADDR, &req)) { #else if (SYS_ERROR == ioctl(dummy, SIOCGIFADDR, &req, sizeof(req))) { #endif sclose(dummy); return NULL; } else { struct in_addr in; union { struct sockaddr_in *sin; struct sockaddr *s; } soadd; soadd.s = &req.ifr_dstaddr; memcpy(&in, &(soadd.sin->sin_addr.s_addr), sizeof(in)); #if defined(HAVE_INET_NTOA_R) ip = inet_ntoa_r(in,buf,buf_size); #else ip = strncpy(buf,inet_ntoa(in),buf_size); ip[buf_size - 1] = 0; #endif } sclose(dummy); } return ip; } /* -- end of if2ip() -- */ #else char *Curl_if2ip(const char *interface, char *buf, int buf_size) { (void) interface; (void) buf; (void) buf_size; return NULL; }
/* <string> .libfile <string> false */ int /* exported for zsysvm.c */ zlibfile(i_ctx_t *i_ctx_p) { os_ptr op = osp; int code; byte cname[DEFAULT_BUFFER_SIZE]; uint clen; gs_parsed_file_name_t pname; stream *s; gx_io_device *iodev_dflt; check_ostack(2); code = parse_file_name(op, &pname, i_ctx_p->LockFilePermissions, imemory); if (code < 0) return code; iodev_dflt = iodev_default(imemory); if (pname.iodev == NULL) pname.iodev = iodev_dflt; if (pname.iodev != iodev_dflt) { /* Non-OS devices don't have search paths (yet). */ code = zopen_file(i_ctx_p, &pname, "r", &s, imemory); if (code >= 0) { code = ssetfilename(s, op->value.const_bytes, r_size(op)); if (code < 0) { sclose(s); return_error(e_VMerror); } } if (code < 0) { push(1); make_false(op); return 0; } make_stream_file(op, s, "r"); } else { ref fref; code = lib_file_open(i_ctx_p->lib_path, imemory, i_ctx_p, pname.fname, pname.len, (char *)cname, sizeof(cname), &clen, &fref); if (code >= 0) { s = fptr(&fref); code = ssetfilename(s, cname, clen); if (code < 0) { sclose(s); return_error(e_VMerror); } } if (code < 0) { if (code == e_VMerror || code == e_invalidfileaccess) return code; push(1); make_false(op); return 0; } ref_assign(op, &fref); } push(1); make_true(op); return 0; }
char *Curl_if2ip(const char *interface, char *buf, int buf_size) { int dummy; char *ip=NULL; if(!interface) return NULL; dummy = socket(AF_INET, SOCK_STREAM, 0); if (SYS_ERROR == dummy) { return NULL; } else { struct ifreq req; size_t len = strlen(interface); memset(&req, 0, sizeof(req)); if(len >= sizeof(req.ifr_name)) { sclose(dummy); return NULL; /* this can't be a fine interface name */ } memcpy(req.ifr_name, interface, len+1); req.ifr_addr.sa_family = AF_INET; #ifdef IOCTL_3_ARGS if (SYS_ERROR == ioctl(dummy, SIOCGIFADDR, &req)) { #else if (SYS_ERROR == ioctl(dummy, SIOCGIFADDR, &req, sizeof(req))) { #endif sclose(dummy); return NULL; } else { struct in_addr in; struct sockaddr_in *s = (struct sockaddr_in *)&req.ifr_dstaddr; memcpy(&in, &s->sin_addr, sizeof(in)); ip = (char *) Curl_inet_ntop(s->sin_family, &in, buf, buf_size); } sclose(dummy); } return ip; } /* -- end of if2ip() -- */ #else char *Curl_if2ip(const char *interf, char *buf, int buf_size) { (void) interf; (void) buf; (void) buf_size; return NULL; }
bool HTTPMessage::Connect(const std::string &host, unsigned short port, int timeout_msec) { struct sockaddr_in addr_out; if ((sock_ = socket(AF_INET, SOCK_STREAM, 0)) == -1) { return false; } memset(&addr_out, 0, sizeof(addr_out)); addr_out.sin_family = AF_INET; addr_out.sin_port = htons(port); if ((addr_out.sin_addr.s_addr = inet_addr(host.c_str())) == INADDR_NONE) { sclose(sock_); return false; } /* Il keepalive della connessione su sistemi unix int optval = 1; size_t optlen = sizeof(optval); ::setsockopt(sock_, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen); */ // su win devo anche cambiare il valore di 7200000msec per il keepalive #ifdef WIN32 tcp_keepalive kp; DWORD returned; kp.onoff = 1; kp.keepalivetime = 5000; // ogni 5 secondi kp.keepaliveinterval = 1000; // un secondo WSAIoctl(sock_, SIO_KEEPALIVE_VALS, (LPVOID) &kp, sizeof(kp), NULL, 0, &returned, NULL, NULL); #endif int rc; if (timeout_msec < 0) rc = connect(sock_, (struct sockaddr *)&addr_out, sizeof(addr_out)); else rc = connect_time(sock_, (struct sockaddr *)&addr_out, sizeof(addr_out), timeout_msec); if (rc == -1) { sclose(sock_); return false; } offset_ = 0; return true; }
int main(int argc, char *argv[]) { socket_t sock; struct sockaddr_in servaddr; char *server; int rc; char bye[3]; int len; server = "127.0.0.1"; sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (sock == SOCKET_BAD) errorout("socket() failed"); memset(&servaddr, 0, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = inet_addr(server); servaddr.sin_port = htons(SERVER_PORT); /* Establish the connection to the echo server */ rc = connect(sock, (struct sockaddr *) &servaddr, sizeof(servaddr)); if (rc < 0) errorout("connect() failed"); printf("Connected!\n"); write(sock, "not spdy", strlen("not spdy")); len = read(sock, bye, sizeof(bye)); printf("Recv: %.*s\n", 3, bye); sclose(sock); return 0; }
/* for normal (OS) files and for filters. */ int file_close_file(stream * s) { stream *stemp = s->strm; gs_memory_t *mem; int code = file_close_disable(s); if (code) return code; /* * Check for temporary streams created for filters. * There may be more than one in the case of a procedure-based filter, * or if we created an intermediate stream to ensure * a large enough buffer. Note that these streams may have been * allocated by file_alloc_stream, so we mustn't free them. */ while (stemp != 0 && stemp->is_temp != 0) { stream *snext = stemp->strm; mem = stemp->memory; if (stemp->is_temp > 1) gs_free_object(mem, stemp->cbuf, "file_close(temp stream buffer)"); s_disable(stemp); stemp = snext; } mem = s->memory; gs_free_object(mem, s->cbuf, "file_close(buffer)"); if (s->close_strm && stemp != 0) return sclose(stemp); return 0; }
int main(int argc, char *argv[]) { socket_t sock; struct sockaddr_in servaddr; char *server; int rc; char bye[3]; int len; struct spindly_phys *phys_client; struct spindly_stream *stream_client; spindly_error_t spint; unsigned char *data; size_t datalen; server = "127.0.0.1"; sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (sock == SOCKET_BAD) errorout("socket() failed"); /* create a spindly handle for the physical connection */ phys_client = spindly_phys_init(SPINDLY_SIDE_CLIENT, SPINDLY_DEFAULT, NULL); memset(&servaddr, 0, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = inet_addr(server); servaddr.sin_port = htons(SERVER_PORT); /* Establish the connection to the echo server */ rc = connect(sock, (struct sockaddr *) &servaddr, sizeof(servaddr)); if (rc < 0) errorout("connect() failed"); printf("Connected! Pretend TLS-NPN succeeded.\n"); /* create a new stream on the physical connection */ spint = spindly_stream_new(phys_client, 0, &stream_client, NULL, NULL); /* get data to send over the socket */ spint = spindly_phys_outgoing(phys_client, &data, &datalen); printf("Ask for a new stream\n"); /* send away the SPDY packet */ rc = send(sock, data, datalen, 0); if(rc > 0) { /* tell spindly how much of that data that was actually sent */ spindly_phys_sent(phys_client, rc); printf("Send %d bytes\n", rc); } /* now wait for data to arrive on the socket and demux it to figure out what the peer says to us */ sleep(5); sclose(sock); return 0; }
/* Make a reusable file stream. */ static int make_rfs(i_ctx_t *i_ctx_p, os_ptr op, stream *fs, long offset, long length) { uint save_space = icurrent_space; uint stream_space = imemory_space((const gs_ref_memory_t *)fs->memory); gs_const_string fname; gs_parsed_file_name_t pname; stream *s; int code; if (sfilename(fs, &fname) < 0) return_error(e_ioerror); code = gs_parse_file_name(&pname, (const char *)fname.data, fname.size, imemory); if (code < 0) return code; if (pname.len == 0) /* %stdin% etc. won't have a filename */ return_error(e_invalidfileaccess); /* can't reopen */ if (pname.iodev == NULL) pname.iodev = iodev_default(imemory); /* Open the file again, to be independent of the source. */ ialloc_set_space(idmemory, stream_space); code = zopen_file(i_ctx_p, &pname, "r", &s, imemory); ialloc_set_space(idmemory, save_space); if (code < 0) return code; if (sread_subfile(s, offset, length) < 0) { sclose(s); return_error(e_ioerror); } s->close_at_eod = false; make_stream_file(op, s, "r"); return 0; }
/* * destroy_thread_data() cleans up async resolver data. * Complementary of ares_destroy. */ static void destroy_thread_data( struct Curl_async *async ) { if ( async->hostname ) { free( async->hostname ); } if ( async->os_specific ) { struct thread_data *td = (struct thread_data*) async->os_specific; curl_socket_t sock = td->dummy_sock; if ( sock != CURL_SOCKET_BAD ) { sclose( sock ); } /* destroy the synchronization objects */ if ( td->mutex_waiting ) { CloseHandle( td->mutex_waiting ); } if ( td->event_resolved ) { CloseHandle( td->event_resolved ); } free( async->os_specific ); } async->hostname = NULL; async->os_specific = NULL; }
int main(void) { FILE *fout; int i, fserial; fout = fopen("rom56.bin", "w"); if (fout == NULL) { fprintf(stderr, "can't open rom56.bin for writing\n"); exit(1); } fserial = sopen("/dev/ttyS0", B19200); if (fserial == -1) { fprintf(stderr, "can't open serial port\n"); exit(1); } for (i=0; i<0x1000; i++) { fputc(sgetc(fserial), fout); printf("."); } fclose(fout); sclose(fserial); return 0; }
/* ** Accept an inbound connection from a peer transport. This call should block until ** a connection has been established. ** When a connection has been accepted, the passed 'connectionid' is set. This will be ** provided by the caller on all subsuquent calls made against the active connection. */ ObxRc iobxInetTransportAccept( void **connectionid ) { int addrlen = sizeof( struct sockaddr_in ); ObxRc rc = OBX_RC_OK; ObxInetConnectionBlock *conblk = NULL; OBXDBGFLOW(("iobxInetTransportAccept() entry, connid=0x%08x\n", *connectionid)); if ( obxServer.active ) { if ( *connectionid ) { conblk = *connectionid; if ( conblk->connected ) { conblk->connected = FALSE; sclose( conblk->fd ); } OBXDBGINFO(("iobxInetTransportAccept() calling accept().\n")); if ( (conblk->fd = accept( obxServer.fd, (struct sockaddr *)&conblk->peer, &addrlen )) >= 0 ) { OBXDBGINFO(("iobxInetTransportAccept() accept() returns.\n")); conblk->connected = TRUE; } else { OBXDBGERR(("[ERROR] iobxInetTransportAccept() socket accept fails.\n")); OBXDBGSOCKERR(); rc = OBX_RC_ERR_SOCKET_ACCEPT; } } else { OBXDBGERR(("[ERROR] iobxInetTransportAccept() bad plist on call.\n")); rc = OBX_RC_ERR_BADPLIST; /* No connection block */ } } else { OBXDBGERR(("[ERROR] iobxInetTransportAccept() socket not listening.\n")); rc = OBX_RC_ERR_SOCKET_NOT_LISTENING; /* listen() not called */ } return rc; }
/* Close the output file and stream. */ int gdev_vector_close_file(gx_device_vector * vdev) { FILE *f = vdev->file; int err; if (vdev->dash_pattern) { gs_free_object(vdev->memory->stable_memory, vdev->dash_pattern, "vector free dash pattern"); vdev->dash_pattern = 0; } if (vdev->bbox_device) { rc_decrement(vdev->bbox_device->icc_struct, "vector_close(bbox_device->icc_struct"); vdev->bbox_device->icc_struct = NULL; gs_free_object(vdev->v_memory, vdev->bbox_device, "vector_close(bbox_device)"); vdev->bbox_device = 0; } if (vdev->strm) { sclose(vdev->strm); gs_free_object(vdev->v_memory, vdev->strm, "vector_close(strm)"); vdev->strm = 0; gs_free_object(vdev->v_memory, vdev->strmbuf, "vector_close(strmbuf)"); vdev->strmbuf = 0; } vdev->file = 0; if (f) { err = ferror(f); /* We prevented sclose from closing the file. */ if (gx_device_close_output_file((gx_device *)vdev, vdev->fname, f) != 0 || err != 0) return_error(gs_error_ioerror); } return 0; }
/* Used within the multi interface. Try next IP address, return TRUE if no more address exists */ static bool trynextip(struct connectdata *conn, int sockindex, bool *connected) { curl_socket_t sockfd; Curl_addrinfo *ai; /* first close the failed socket */ sclose(conn->sock[sockindex]); conn->sock[sockindex] = CURL_SOCKET_BAD; *connected = FALSE; if(sockindex != FIRSTSOCKET) return TRUE; /* no next */ /* try the next address */ ai = conn->ip_addr->ai_next; while (ai) { sockfd = singleipconnect(conn, ai, 0L, connected); if(sockfd != CURL_SOCKET_BAD) { /* store the new socket descriptor */ conn->sock[sockindex] = sockfd; conn->ip_addr = ai; Curl_store_ip_addr(conn); return FALSE; } ai = ai->ai_next; } return TRUE; }
int pipeback_shared (const char *filename, const char *argv[], int exec_type) { struct sigaction *sigact; char mbuf[256]; sigact = scalloc (sizeof (struct sigaction), 1); sigact->sa_handler = SIG_IGN; #ifdef NOCLDWAIT sigact->sa_flags = SA_NOCLDWAIT; #endif if (sigaction (SIGCHLD, sigact, NULL)) { error ("Error protecting against zombies!"); exit (EXIT_FAILURE); } if (pipe (local_pipe)) { error ("Error opening pipeback pipe!"); exit (EXIT_FAILURE); } if (PipebackChildPID = fork()) { sclose (local_pipe[1]); return local_pipe[0]; } else { sclose (local_pipe[0]); sclose (1); dup (local_pipe[1]); sclose (2); dup (local_pipe[1]); sclose (local_pipe[1]); if (0 == exec_type) { execv (filename, (char**) argv); } else { execvp (filename, (char**) argv); } sprintf (mbuf, "Pipeback was unable to load program %s", filename); error (mbuf); } }
/* * Close a socket. * * 'conn' can be NULL, beware! */ int Curl_closesocket(struct connectdata *conn, curl_socket_t sock) { if(conn && conn->fclosesocket) return conn->fclosesocket(conn->closesocket_client, sock); else return sclose(sock); }
/* * Curl_getaddrinfo() when built ipv6-enabled (non-threading version). * * Returns name information about the given hostname and port number. If * successful, the 'addrinfo' is returned and the forth argument will point to * memory we need to free after use. That memory *MUST* be freed with * Curl_freeaddrinfo(), nothing else. */ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, char *hostname, int port, int *waitp) { struct addrinfo hints, *res; int error; char sbuf[NI_MAXSERV]; curl_socket_t s; int pf; struct SessionHandle *data = conn->data; *waitp=0; /* don't wait, we have the response now */ /* see if we have an IPv6 stack */ s = socket(PF_INET6, SOCK_DGRAM, 0); if (s < 0) { /* Some non-IPv6 stacks have been found to make very slow name resolves * when PF_UNSPEC is used, so thus we switch to a mere PF_INET lookup if * the stack seems to be a non-ipv6 one. */ pf = PF_INET; } else { /* This seems to be an IPv6-capable stack, use PF_UNSPEC for the widest * possible checks. And close the socket again. */ sclose(s); /* * Check if a more limited name resolve has been requested. */ switch(data->set.ip_version) { case CURL_IPRESOLVE_V4: pf = PF_INET; break; case CURL_IPRESOLVE_V6: pf = PF_INET6; break; default: pf = PF_UNSPEC; break; } } memset(&hints, 0, sizeof(hints)); hints.ai_family = pf; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_CANONNAME; snprintf(sbuf, sizeof(sbuf), "%d", port); error = getaddrinfo(hostname, sbuf, &hints, &res); if (error) { infof(data, "getaddrinfo(3) failed for %s:%d\n", hostname, port); return NULL; } return res; }
/* return zero for success, -ve for error, +1 for continue */ static int lib_file_open_search_with_combine(gs_file_path_ptr lib_path, const gs_memory_t *mem, i_ctx_t *i_ctx_p, const char *fname, uint flen, char *buffer, int blen, uint *pclen, ref *pfile, gx_io_device *iodev, bool starting_arg_file, char *fmode) { stream *s; const gs_file_path *pfpath = lib_path; uint pi; for (pi = 0; pi < r_size(&pfpath->list); ++pi) { const ref *prdir = pfpath->list.value.refs + pi; const char *pstr = (const char *)prdir->value.const_bytes; uint plen = r_size(prdir), blen1 = blen; gs_parsed_file_name_t pname; gp_file_name_combine_result r; /* We need to concatenate and parse the file name here * if this path has a %device% prefix. */ if (pstr[0] == '%') { int code; /* We concatenate directly since gp_file_name_combine_* * rules are not correct for other devices such as %rom% */ code = gs_parse_file_name(&pname, pstr, plen, mem); if (code < 0) continue; memcpy(buffer, pname.fname, pname.len); memcpy(buffer+pname.len, fname, flen); code = pname.iodev->procs.open_file(pname.iodev, buffer, pname.len + flen, fmode, &s, (gs_memory_t *)mem); if (code < 0) continue; make_stream_file(pfile, s, "r"); /* fill in the buffer with the device concatenated */ memcpy(buffer, pstr, plen); memcpy(buffer+plen, fname, flen); *pclen = plen + flen; return 0; } else { r = gp_file_name_combine(pstr, plen, fname, flen, false, buffer, &blen1); if (r != gp_combine_success) continue; if (iodev_os_open_file(iodev, (const char *)buffer, blen1, (const char *)fmode, &s, (gs_memory_t *)mem) == 0) { if (starting_arg_file || check_file_permissions_aux(i_ctx_p, buffer, blen1) >= 0) { *pclen = blen1; make_stream_file(pfile, s, "r"); return 0; } sclose(s); return_error(e_invalidfileaccess); } } } return 1; }
int sfclose(stream *s) { /* no need to flush since these are 'read' only */ gs_memory_t *mem = s->memory; sclose(s); gs_free_object(mem, s, "sfclose(stream)"); return 0; }
/* ** Clean up all internals */ ObxRc iobxInetTransportTerminate( void ) { OBXDBGFLOW(("iobxInetTransportTerminate() entry.\n")); free(obxMeta.host); obxMeta.host = NULL; if (obxServer.active) { sclose(obxServer.fd); obxServer.active = FALSE; } return OBX_RC_OK; }
int sscanf(const char *s, const char *fmt, ...){ int n; FILE *f=sopenr(s); va_list args; va_start(args, fmt); n=vfscanf(f, fmt, args); va_end(args); sclose(f); return n; }
if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope, unsigned int remote_scope_id, const char *interf, char *buf, int buf_size) { struct ifreq req; struct in_addr in; struct sockaddr_in *s; curl_socket_t dummy; size_t len; (void)remote_scope; (void)remote_scope_id; if(!interf || (af != AF_INET)) return IF2IP_NOT_FOUND; len = strlen(interf); if(len >= sizeof(req.ifr_name)) return IF2IP_NOT_FOUND; dummy = socket(AF_INET, SOCK_STREAM, 0); if(CURL_SOCKET_BAD == dummy) return IF2IP_NOT_FOUND; memset(&req, 0, sizeof(req)); memcpy(req.ifr_name, interf, len+1); req.ifr_addr.sa_family = AF_INET; if(ioctl(dummy, SIOCGIFADDR, &req) < 0) { sclose(dummy); /* With SIOCGIFADDR, we cannot tell the difference between an interface that does not exist and an interface that has no address of the correct family. Assume the interface does not exist */ return IF2IP_NOT_FOUND; } s = (struct sockaddr_in *)&req.ifr_addr; memcpy(&in, &s->sin_addr, sizeof(in)); Curl_inet_ntop(s->sin_family, &in, buf, buf_size); sclose(dummy); return IF2IP_FOUND; }
int vsprintf(char *buf, const char *fmt, va_list args){ int n; FILE *f=sopenw(); if(f==NULL) return 0; setvbuf(f, buf, _IOFBF, 100000); n=vfprintf(f, fmt, args); sclose(f); return n; }
void MainWindow::connections() { connect(open, SIGNAL(triggered()), this, SLOT(sopen())); connect(save, SIGNAL(triggered()), this, SLOT(ssave())); connect(revert, SIGNAL(triggered()), this, SLOT(srevert())); connect(close, SIGNAL(triggered()), this, SLOT(sclose())); connect(calculator, SIGNAL(triggered()), this, SLOT(scalculator())); connect(bnPlus, SIGNAL(pressed()), this, SLOT(plus())); connect(bnMinus, SIGNAL(pressed()), this, SLOT(minus())); connect(bnTimes, SIGNAL(pressed()), this, SLOT(times())); connect(bnDivide, SIGNAL(pressed()), this, SLOT(divide())); }
/* * Curl_ipvalid() checks what CURL_IPRESOLVE_* requirements that might've * been set and returns TRUE if they are OK. */ bool Curl_ipvalid(struct SessionHandle *data) { if(data->set.ip_version == CURL_IPRESOLVE_V6) { /* see if we have an IPv6 stack */ curl_socket_t s = socket(PF_INET6, SOCK_DGRAM, 0); if(s == CURL_SOCKET_BAD) /* an ipv6 address was requested and we can't get/use one */ return FALSE; sclose(s); } return TRUE; }
void ares__close_sockets(ares_channel channel, struct server_state *server) { struct send_request *sendreq; /* Free all pending output buffers. */ while (server->qhead) { /* Advance server->qhead; pull out query as we go. */ sendreq = server->qhead; server->qhead = sendreq->next; if (sendreq->data_storage != NULL) free(sendreq->data_storage); free(sendreq); } server->qtail = NULL; /* Reset any existing input buffer. */ if (server->tcp_buffer) free(server->tcp_buffer); server->tcp_buffer = NULL; server->tcp_lenbuf_pos = 0; /* Reset brokenness */ server->is_broken = 0; /* Close the TCP and UDP sockets. */ if (server->tcp_socket != ARES_SOCKET_BAD) { SOCK_STATE_CALLBACK(channel, server->tcp_socket, 0, 0); sclose(server->tcp_socket); server->tcp_socket = ARES_SOCKET_BAD; server->tcp_connection_generation = ++channel->tcp_connection_generation; } if (server->udp_socket != ARES_SOCKET_BAD) { SOCK_STATE_CALLBACK(channel, server->udp_socket, 0, 0); sclose(server->udp_socket); server->udp_socket = ARES_SOCKET_BAD; } }
int main(void) { struct stream *i = sopen_fd("stdin", 0); struct stream *o = sopen_fd("stdout", 1); int c, d, nl = 1; c = sgetc(i); for (;;) { if (c == '/') { if ((d = sgetc(i)) == '/') { // skipping a comment... while ((c = sgetc(i)) >= 0 && c != '\n') ; if (nl) { c = sgetc(i); continue; } } else { sputc(o, c); c = d; } } if (c < 0) break; sputc(o, c); nl = (c == '\n'); c = sgetc(i); } sclose(o); sclose(i); return 0; }
void dictinit(char *fname) { Stream *fin; Block *b; fin = sopen(fname, OREAD); while(b = getblock(fin)){ setblock(b); free(b); } sclose(fin); }
/* Used within the multi interface. Try next IP address, return TRUE if no more address exists or error */ static CURLcode trynextip(struct connectdata *conn, int sockindex, bool *connected) { curl_socket_t sockfd; Curl_addrinfo *ai; /* First clean up after the failed socket. Don't close it yet to ensure that the next IP's socket gets a different file descriptor, which can prevent bugs when the curl_multi_socket_action interface is used with certain select() replacements such as kqueue. */ curl_socket_t fd_to_close = conn->sock[sockindex]; conn->sock[sockindex] = CURL_SOCKET_BAD; *connected = FALSE; if(sockindex != FIRSTSOCKET) { sclose(fd_to_close); return CURLE_COULDNT_CONNECT; /* no next */ } /* try the next address */ ai = conn->ip_addr->ai_next; while(ai) { CURLcode res = singleipconnect(conn, ai, 0L, &sockfd, connected); if(res) return res; if(sockfd != CURL_SOCKET_BAD) { /* store the new socket descriptor */ conn->sock[sockindex] = sockfd; conn->ip_addr = ai; sclose(fd_to_close); return CURLE_OK; } ai = ai->ai_next; } sclose(fd_to_close); return CURLE_COULDNT_CONNECT; }
int sprintf(char *buf, const char *fmt, ...){ int n; va_list args; FILE *f=sopenw(); if(f==NULL) return 0; setvbuf(f, buf, _IOFBF, 100000); va_start(args, fmt); n=vfprintf(f, fmt, args); va_end(args); sclose(f); return n; }