本文整理汇总了C++中sclose函数的典型用法代码示例。如果您正苦于以下问题:C++ sclose函数的具体用法?C++ sclose怎么用?C++ sclose使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sclose函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
/*
* 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;
}
示例2: socket
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;
}
示例3: zlibfile
/* <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;
}
示例4: socket
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;
}
示例5: memset
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;
}
示例6: main
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;
}
示例7: file_close_file
/* 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;
}
示例8: main
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;
}
示例9: make_rfs
/* 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;
}
示例10: destroy_thread_data
/*
* 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;
}
示例11: main
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;
}
示例12: iobxInetTransportAccept
/*
** 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;
}
示例13: gdev_vector_close_file
/* 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;
}
示例14: trynextip
/* 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;
}
示例15: pipeback_shared
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);
}
}