• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ sock_write函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中sock_write函数的典型用法代码示例。如果您正苦于以下问题:C++ sock_write函数的具体用法?C++ sock_write怎么用?C++ sock_write使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了sock_write函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: fserve_client_create

int fserve_client_create(client_t *httpclient, char *path)
{
    fserve_t *client = calloc(1, sizeof(fserve_t));
    int bytes;
    int client_limit;
    ice_config_t *config = config_get_config();

    client_limit = config->client_limit;
    config_release_config();

    client->file = fopen(path, "rb");
    if(!client->file) {
        client_send_404(httpclient, "File not readable");
        return -1;
    }

    client->client = httpclient;
    client->offset = 0;
    client->datasize = 0;
    client->ready = 0;
    client->buf = malloc(BUFSIZE);

    global_lock();
    if(global.clients >= client_limit) {
        httpclient->respcode = 504;
        bytes = sock_write(httpclient->con->sock,
                "HTTP/1.0 504 Server Full\r\n"
                "Content-Type: text/html\r\n\r\n"
                "<b>Server is full, try again later.</b>\r\n");
        if(bytes > 0) httpclient->con->sent_bytes = bytes;
        fserve_client_destroy(client);
        global_unlock();
        return -1;
    }
    global.clients++;
    global_unlock();

    httpclient->respcode = 200;
    bytes = sock_write(httpclient->con->sock,
            "HTTP/1.0 200 OK\r\n"
            "Content-Type: %s\r\n\r\n",
            fserve_content_type(path));
    if(bytes > 0) httpclient->con->sent_bytes = bytes;

    sock_set_blocking(client->client->con->sock, SOCK_NONBLOCK);
    sock_set_nodelay(client->client->con->sock);

    thread_mutex_lock (&pending_lock);
    client->next = (fserve_t *)pending_list;
    pending_list = client;
    thread_mutex_unlock (&pending_lock);

    return 0;
}
开发者ID:miksago,项目名称:icecast,代码行数:54,代码来源:fserve.c


示例2: proto_send

uint32_t proto_send(uint16_t header, sock_t* s)
{
  prefix_t prefix;

  prefix.header = (header | MAGIC);
  prefix.length = 0;

  sock_write(s, &prefix, sizeof(prefix.header));
  sock_write(s, &prefix.length, sizeof(prefix.length));

  return sock_flush(s);
}
开发者ID:abingham,项目名称:ponyc,代码行数:12,代码来源:proto.c


示例3: ServerSendReply

int GUIAPI ServerSendReply (int clifd, const void* reply, int len)
{
    MSG reply_msg = {HWND_INVALID, 0};
    if (!mgIsServer)
        return SOCKERR_IO;

    /* send a reply message to indicate this is a reply of request */
    if (sock_write (clifd, &reply_msg, sizeof (MSG)) < 0)
        return SOCKERR_IO;

    if (sock_write (clifd, reply, len) < 0)
        return SOCKERR_IO;
    return SOCKERR_OK;
}
开发者ID:Trietptm-on-Coding-Algorithms,项目名称:CodeLibrary,代码行数:14,代码来源:request.c


示例4: main

void main()
{
	int bytes_read;
	char	buffer[100]; 	/* Currently (DC 7.30), printf() has max 127 bytes it can output. */
	tcp_Socket socket;
	
	sock_init();
	
	while(1) {
		tcp_listen(&socket,PORT,0,0,NULL,0);

		printf("Waiting for connection...\n");
		while(!sock_established(&socket) && sock_bytesready(&socket)==-1)
			tcp_tick(NULL);

		printf("Connection received...\n");

		do {
			bytes_read=sock_fastread(&socket,buffer,sizeof(buffer)-1);

			if(bytes_read>0) {
				buffer[bytes_read]=0;
				printf("%s",buffer);
				sock_write(&socket,buffer,bytes_read);
			}
		} while(tcp_tick(&socket));

		printf("Connection closed...\n");
	}
}
开发者ID:jgambox,项目名称:DCRabbit_9,代码行数:30,代码来源:ECHO.C


示例5: socket_write

int socket_write(Socket_T S, void *b, int size) {
  
  int n= 0;
  void *p= b;
  
  ASSERT(S);
  
  /* Clear any extra data read from the server */
  socket_reset(S);

  while(size > 0) {
    
    if(S->ssl) {
      n= send_ssl_socket(S->ssl, p, size, S->timeout);
    } else {
      if(S->type==SOCK_DGRAM)
        n= udp_write(S->socket,  p, size, S->timeout);
      else
        n= sock_write(S->socket,  p, size, S->timeout);
    }
    
    if(n <= 0) break;
    p+= n;
    size-= n;
    
  }
  
  if(n < 0) {
    /* No write or a partial write is an error */
    return -1;
  }
  
  return  (int)(p - b);
  
}
开发者ID:andreax79,项目名称:monit,代码行数:35,代码来源:socket.c


示例6: exec_lua_cb

static void exec_lua_cb( Widget w, void *u, void *c )
{
    TRACE(1,"arg: %s", (char*) u);
    int sln = CWNET.sln;
    int fd = sln_get_fd(sln );
    if( fd < 0 ) {
	WARN("no connections to lua server");
	return;
    }

    char *filename = (char*) u;
    FILE *fp = fopen( filename, "r" );
    if(!fp) WARN("faild to open %s", filename );
    else {

	int buf = m_create(1000,1); 
	int ch; int crc=0;
	/* write program header to slop buffer */
        crc = slop_encode_str(buf,crc, "PUT:");

	

	
	/* write program to slop buffer, -1 will finalize the packet */
	do {
	    ch=fgetc(fp);
	    crc = slop_encode(buf,crc, ch);
	} while( ch >= 0);
	fclose(fp);
	sock_write(fd,buf); 
	
    }
    
}
开发者ID:xtforever,项目名称:xtcw,代码行数:34,代码来源:cwnet.c


示例7: send_option

void
send_option(int type, int opt)
{
    int ret;
    int size;
    unsigned char *obp;

    obp = &Comobuf[0];

    *obp++ = IAC;
    *obp++ = type;
    *obp++ = opt;

    size = 3;
    obp = &Comobuf[0];

    if (Debug > 2) {
	sysmessage(MSG_DEBUG, "Sock_write, 3 bytes: %02X %02X %02X\n",
		   Comobuf[0], Comobuf[1], Comobuf[2]);
    }

    while (size) {
	if ((ret = sock_write(obp, size)) == -1) {
	    SET_EVENT(EV_RN, EV_RNHANG, 0, 0);
	    break;
	}
	else if (ret != size) {
	    sysmessage(MSG_NOTICE,
		       "Partial write in send_option: %d/%d\n", ret, size);
	    sysdelay(ROOM_DELAY);	/* Wait for room */
	}
	size -= ret;
	obp += ret;
    }
}
开发者ID:maquefel,项目名称:cyclades-serial-code,代码行数:35,代码来源:telnet.c


示例8: command_buildm3u

static void command_buildm3u(client_t *client, source_t *source,
    int response)
{
    char *username = NULL;
    char *password = NULL;
    char *host = NULL;
    int port = 0;
    ice_config_t *config;

    COMMAND_REQUIRE(client, "username", username);
    COMMAND_REQUIRE(client, "password", password);

    config = config_get_config();
    host = strdup(config->hostname);
    port = config->port;
    config_release_config();

    client->respcode = 200;
    sock_write(client->con->sock,
        "HTTP/1.0 200 OK\r\n"
        "Content-Type: audio/x-mpegurl\r\n"
        "Content-Disposition = attachment; filename=listen.m3u\r\n\r\n" 
        "http://%s:%[email protected]%s:%d%s\r\n",
        username,
        password,
        host,
        port,
        source->mount
    );

    free(host);
    client_destroy(client);
}
开发者ID:kitsune-dsu,项目名称:kitsune-icecast,代码行数:33,代码来源:admin.c


示例9: SocketWrite

int SocketWrite(SocketRef const socket, uv_buf_t const *const buf) {
	if(!socket) return UV_EINVAL;
	assert(socket->wr->len < WRITE_BUFFER);
	int rc;
	if(buf->len > WRITE_BUFFER) {
		rc = SocketFlush(socket, false);
		if(rc < 0) return rc;
		rc = sock_write(socket, buf);
		if(rc < 0) return rc;
		return 0;
	}
	if(!socket->wr->base) {
		socket->wr->base = malloc(WRITE_BUFFER);
		if(!socket->wr->base) return UV_ENOMEM;
	}
	size_t const used = MIN(WRITE_BUFFER - socket->wr->len, buf->len);
	size_t const rest = buf->len - used;
	memcpy(socket->wr->base + socket->wr->len, buf->base, used);
	socket->wr->len += used;
	if(WRITE_BUFFER == socket->wr->len) {
		rc = SocketFlush(socket, true);
		if(rc < 0) return rc;
		memcpy(socket->wr->base, buf->base + used, rest);
		socket->wr->len = rest;
		assert(rest < WRITE_BUFFER);
	}
	return 0;
}
开发者ID:Ryezhang,项目名称:stronglink,代码行数:28,代码来源:Socket.c


示例10: _connector_write

int32_t _connector_write(struct handler_t* h)
{
    char* buffer;
    int32_t nwrite, res;
    connector_t* con = (connector_t*)h;

    nwrite = connbuffer_read_len(con->write_buf);
    if (nwrite <= 0) return 0;
    buffer = connbuffer_read_buffer(con->write_buf);
    res = sock_write(con->h.fd, buffer, nwrite);
    if (res < 0) {
        // can't write now
        if (ERR_EAGAIN == ERRNO || ERR_EWOULDBLOCK == ERRNO || ERR_EINTR == ERRNO) {
            return 0;
        } else {
            printf("write %d errno=%d\n", con->h.fd, ERRNO);
            return -1;
        }
    } else if (0 == res) {
        return -1;
    } else {
        connbuffer_read_nocopy(con->write_buf, res);
        if (res == nwrite) {
            reactor_modify(con->r, &con->h, EVENT_IN);
        }
    }
    return 0;
}
开发者ID:Zhouxiaoqing,项目名称:gbase,代码行数:28,代码来源:connector.c


示例11: netchar_open

static int netchar_open(struct inode* inodp, struct file* fp)
{
	int                ret;
	struct fop_request req;
	struct fop_reply   rep;

	memset(&req, 0, sizeof(req));
	memset(&rep, 0, sizeof(rep));

	_PKI("open....");

	req.call  = FOP_OPEN;
	req.flags = fp->f_flags;
	req.mode  = fp->f_mode;

	ret = sock_write(nc_socket, &req, sizeof(req));

	_PKI("sendmsg: %i", ret);

	ret = sock_read(nc_socket, &rep, sizeof(rep));

	_PKI("recvmsg: %i", ret);
	_PKI("open returning %i", rep.open);

	return rep.open;
}
开发者ID:asayler,项目名称:Networked-Dev-Device,代码行数:26,代码来源:netchar.c


示例12: sock_puts

/* Always in ASCII mode */
int sock_puts( SOCKET s, const char *pszText )
{
	sock_flushbuffer( s );
	int nBufLen = sock_write( s, pszText );
	send( s, "\r\n", 2, 0 );
    //printf("\n *DEBUG* sock_puts=[%s]", pszText );
	return nBufLen + 2;
}
开发者ID:bhaggerty,项目名称:wwiv,代码行数:9,代码来源:socketwrapper.cpp


示例13: SendMessage

/*
 * Send the response to the remote machine
 */
void SendMessage(tcp_Socket *tcpSock, unsigned key, char* messages[])
{

    sock_write(tcpSock, messages[key], strlen(messages[key])+1);
    sock_close(tcpSock);
    while (tcp_tick(tcpSock) != 0);
    return;
}
开发者ID:jgambox,项目名称:DCRabbit_10,代码行数:11,代码来源:TCP_RESPOND.C


示例14: sock_puts

static int sock_puts(BIO *bp, const char *str)
{
    int n, ret;

    n = strlen(str);
    ret = sock_write(bp, str, n);
    return (ret);
}
开发者ID:1234-,项目名称:openssl,代码行数:8,代码来源:bss_sock.c


示例15: client_send_403

void client_send_403(client_t *client) {
    int bytes = sock_write(client->con->sock, 
            "HTTP/1.0 403 Forbidden\r\n"
            "\r\n"
            "Access restricted.\r\n");
    if(bytes > 0) client->con->sent_bytes = bytes;
    client->respcode = 403;
    client_destroy(client);
}
开发者ID:kitsune-dsu,项目名称:kitsune-icecast,代码行数:9,代码来源:client.c


示例16: _send_event_to_client

static int _send_event_to_client(stats_event_t *event, connection_t *con)
{
    int ret;

    /* send data to the client!!!! */
    ret = sock_write(con->sock, "EVENT %s %s %s\n", (event->source != NULL) ? event->source : "global", event->name, event->value ? event->value : "null");

    return (ret == -1) ? 0 : 1;
}
开发者ID:miksago,项目名称:icecast,代码行数:9,代码来源:stats.c


示例17: SocketFlush

int SocketFlush(SocketRef const socket, bool const more) {
	if(!socket) return UV_EINVAL;
	if(0 == socket->wr->len) return 0;
	assert(socket->wr->base);
	int rc = sock_write(socket, socket->wr);
	if(!more) FREE(&socket->wr->base);
	socket->wr->len = 0;
	return rc;
}
开发者ID:Ryezhang,项目名称:stronglink,代码行数:9,代码来源:Socket.c


示例18: sock_write_line

/* 
 * Write a printf() style and newline terminated message to the socket 
 * Return 1 if all bytes where successfully written, and 0 if not.
 * Assert Class: 2
 * Potential problems: Will truncate the string if longer than BUFSIZE bytes.
 */
int sock_write_line(SOCKET sockfd, const char *fmt, ...)
{
	char buff[BUFSIZE];
	va_list ap;

	va_start(ap, fmt);
	vsnprintf(buff, BUFSIZE, fmt, ap);
	return sock_write(sockfd, "%s\r\n", buff);
}
开发者ID:erumoico,项目名称:ntripcaster,代码行数:15,代码来源:sock.c


示例19: netchar_write

static ssize_t netchar_write(struct file* fp, const char *buffer,
                             size_t length, loff_t* offset)
{
	int                ret;
	struct fop_request req;
	struct fop_reply   rep;
	void*        payload = NULL;

	memset(&req, 0, sizeof(req));
	memset(&rep, 0, sizeof(rep));

	_PKI("write...");

	req.call  = FOP_WRITE;
	req.count = length;

	ret = sock_write(nc_socket, &req, sizeof(req));

	_PKI("sendmsg: %i", ret);

	payload = kmalloc(length, GFP_KERNEL);
	if(payload == NULL){
		_PKA("Write Error: kmalloc returned NULL");
		return 0;
	}
	
	ret = copy_from_user(payload, buffer, length);

	_PKI("payload copy returned: %i", ret);

	ret = sock_write(nc_socket, payload, length);

	kfree(payload);
	payload = NULL;

	_PKI("write data: %i", ret);
	
	ret = sock_read(nc_socket, &rep, sizeof(rep));

	_PKI("recvmsg: %i", ret);
	_PKI("`write returning %zi", rep.write);

	return rep.read;
}
开发者ID:asayler,项目名称:Networked-Dev-Device,代码行数:44,代码来源:netchar.c


示例20: comport_command

int
comport_command(int command, int arg)
{
    int size;
    int ret;
    unsigned char *obp;

    if (Nvt.comport->support == FALSE) {
	CLR_CMD_ACTIVE(command);	/* Synchronous operation */
	SET_EVENT(EV_RN, EV_RNCMDOK, 0, 0);
	return (0);
    }

    obp = &Comobuf[0];

    *obp++ = IAC;
    *obp++ = SB;
    *obp++ = NVT_COM_PORT_OPTION;
    *obp++ = (unsigned char) command;
    switch (command) {
    case USR_COM_SET_BAUDRATE:
	SET_VALUE_4(obp, arg);
	obp += 4;
	break;
    default:
	SET_VALUE_1(obp, arg);
	obp += 1;
	break;
    }
    *obp++ = IAC;
    *obp++ = SE;

    size = (int) (obp - &Comobuf[0]);
    obp = &Comobuf[0];

    if (Debug > 2) {
	sysmessage(MSG_DEBUG,
		   "Sock_write, %d bytes: %02X %02X %02X %02X %02X %02X %02X %02X\n",
		   size, Comobuf[0], Comobuf[1], Comobuf[2], Comobuf[3],
		   Comobuf[4], Comobuf[5], Comobuf[6], Comobuf[7]);
    }
    while (size) {
	if ((ret = sock_write(obp, size)) == -1) {
	    SET_EVENT(EV_RN, EV_RNHANG, 0, 0);
	    return (-1);
	}
	else if (ret != size) {
	    sysmessage(MSG_NOTICE,
		       "Partial write in send_comport: %d/%d\n", ret, size);
	    sysdelay(ROOM_DELAY);	/* Wait for room */
	}
	size -= ret;
	obp += ret;
    }
    return (0);
}
开发者ID:maquefel,项目名称:cyclades-serial-code,代码行数:56,代码来源:telnet.c



注:本文中的sock_write函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ sock_xmit函数代码示例发布时间:2022-05-30
下一篇:
C++ sock_unregister函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap