本文整理汇总了C++中write_socket函数的典型用法代码示例。如果您正苦于以下问题:C++ write_socket函数的具体用法?C++ write_socket怎么用?C++ write_socket使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了write_socket函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: send_response
static void send_response(wurfld_connection_context *ctx) {
char *useragent = ctx->useragent;
DEBUG1("Worker %p is looking up useragent : %s", pthread_self(), useragent);
// this might be unnecessary if libwurfl is thread-safe
// XXX - needs to be checked
wurfld_get_capabilities(useragent, ctx->output);
if (use_http) {
char response_header[1024];
sprintf(response_header, "%s 200 OK\r\n"
"Content-Type: application/json\r\n"
"Content-length: %d\r\n"
"Server: wurfld\r\n"
"Connection: Close\r\n\r\n",
ctx->is_http10 ? "HTTP/1.0" : "HTTP/1.1", fbuf_used(ctx->output));
int err = write_socket(ctx->fd, response_header, strlen(response_header));
if (err != 0) {
ERROR("(%p) Can't write the response header : %s", pthread_self(), strerror(errno));
}
}
if (write_socket(ctx->fd, fbuf_data(ctx->output), fbuf_used(ctx->output)) != 0) {
ERROR("(%p) Can't write the response data : %s", pthread_self(), strerror(errno));
}
}
示例2: send_group
/*
Sends the group at group_index to the user on the socket provided
*/
void send_group(int group_index, int socket){
char message[2048];
memset(message,'\0',sizeof(message));
strcat(message,"S");
int i;
struct chat_group *cg = all_groups[group_index];
printf("Number of users in this group, server side: %d\n",cg->num_users);
//First, send the number of users that are in the group:
int network_num_users = htonl(cg->num_users);
write_socket(socket,&network_num_users,sizeof(int));
//Next, send the message with the users:
for(i = 0; i < cg->num_users; ++i){
strcat(message,":");
strcat(message,cg->users[i]->username);
strcat(message,":");
strcat(message,cg->users[i]->IP);
}
strcat(message,"::");
//printf("Message to send: %s\n", message);
//Send the size of the message
int network_message_size = htonl(sizeof(message));
write_socket(socket,&network_message_size,sizeof(int));
//Send the message itself
write_socket(socket,message,sizeof(message));
}
示例3: openSocket
void KCrash::startDrKonqi(const char *argv[], int argc)
{
int socket = openSocket();
if(socket < -1)
{
startDirectly(argv, argc);
return;
}
klauncher_header header;
header.cmd = LAUNCHER_EXEC_NEW;
const int BUFSIZE = 8192; // make sure this is big enough
char buffer[BUFSIZE + 10];
int pos = 0;
long argcl = argc;
memcpy(buffer + pos, &argcl, sizeof(argcl));
pos += sizeof(argcl);
for(int i = 0; i < argc; ++i)
{
int len = strlen(argv[i]) + 1; // include terminating \0
if(pos + len > BUFSIZE)
{
fprintf(stderr, "BUFSIZE in KCrash not big enough!\n");
startDirectly(argv, argc);
return;
}
memcpy(buffer + pos, argv[i], len);
pos += len;
}
long env = 0;
memcpy(buffer + pos, &env, sizeof(env));
pos += sizeof(env);
long avoid_loops = 0;
memcpy(buffer + pos, &avoid_loops, sizeof(avoid_loops));
pos += sizeof(avoid_loops);
header.arg_length = pos;
write_socket(socket, (char *)&header, sizeof(header));
write_socket(socket, buffer, pos);
if(read_socket(socket, (char *)&header, sizeof(header)) < 0 || header.cmd != LAUNCHER_OK)
{
startDirectly(argv, argc);
return;
}
long pid;
read_socket(socket, buffer, header.arg_length);
pid = *((long *)buffer);
alarm(0); // Seems we made it....
for(;;)
{
if(kill(pid, 0) < 0)
_exit(253);
sleep(1);
// the debugger should stop this process anyway
}
}
示例4: send_list
/*
This function accepts a socket as a parameter and sends the list of current groups to that socket.
*/
void send_list(int socket) {
// First, send an int of the total number of groups
int network_num_groups = htonl(num_groups);
write_socket(socket,&network_num_groups,sizeof(int));
//Next, go through all of the groups and send them to the user.
int i;
for(i = 0; i < num_groups; i++){
write_socket(socket,all_groups[i]->groupname, NAME_SIZE);
}
}
示例5: Cmd_operater
int Cmd_operater(int sockd)
{
char cmd[7],message[256];
int i;
int flag=0;
char buffer[512];
char send_buffer[512];
while(1)
{
if(timeout(sockd,200)>0)
{
memset(buffer,'\0',512);
memset(send_buffer,'\0',512);
read_socket(sockd,buffer,512);
printf("recv:%s\n",buffer);
sprintf(send_buffer,"server recv:%s\n",buffer);
write_socket(sockd,send_buffer,512);
}
else
{
close(sockd);
break;
}
}
}
示例6: send_null_session_msg
BOOL
send_null_session_msg (int fd)
{
ssize_t ret;
uint32 blank = 0;
size_t len = 4;
size_t nwritten = 0;
char *buffer = (char *) ␣
while (nwritten < len)
{
ret = write_socket (fd, buffer + nwritten, len - nwritten);
if (ret <= 0)
{
DEBUG (0,
("send_null_session_msg: Error writing %d bytes to client. %d. Exiting\n",
(int) len, (int) ret));
close_sockets ();
exit (1);
}
nwritten += ret;
}
DEBUG (10, ("send_null_session_msg: sent 4 null bytes to client.\n"));
return True;
}
示例7: time_out
/*
* Function name: time_out
* Description : Called after some time to close the connection.
*/
static void
time_out()
{
write_socket("Application time out.\n");
destruct();
}
示例8: catch_tell
/*
* Function name: catch_tell
* Description: This is the text that normal players gets written to
* their sockets.
*/
void
catch_tell(string str)
{
int il;
string pattern, func, euid;
if (query_interactive(this_object())) // Monster is possessed
{
write_socket(str);
return;
}
if (!sizeof(trig_patterns))
return;
cur_text = str;
for (il = 0; il < sizeof(trig_patterns); il++)
{
if (stringp(trig_patterns[il]))
{
pattern = process_string(trig_patterns[il], 1);
if (trig_check(str, pattern, trig_functions[il]))
return;
}
}
}
示例9: quit
/*
* Function name: quit
* Description : Remove the object from memory when the player aborts.
*/
static void
quit()
{
write_socket("\nAborting application.\n");
destruct();
}
示例10: telnet_send_naws
static void telnet_send_naws(struct session *ses)
{
unsigned char nego[128], *np;
#define PUTBYTE(b) if ((b)==255) *np++=255; *np++=(b);
np=nego;
*np++=IAC;
*np++=SB;
*np++=NAWS;
PUTBYTE(COLS/256);
PUTBYTE(COLS%256);
PUTBYTE((LINES-1-!!isstatus)/256);
PUTBYTE((LINES-1-!!isstatus)%256);
*np++=IAC;
*np++=SE;
write_socket(ses, (char*)nego, np-nego);
#ifdef TELNET_DEBUG
{
char buf[BUFFER_SIZE], *b=buf;
int neb=np-nego-2;
np=nego+3;
b=buf+sprintf(buf, "IAC SB NAWS ");
while (np-nego<neb)
b+=sprintf(b, "<%u> ", *np++);
b+=sprintf(b, "IAC SE");
tintin_printf(ses, "~8~[telnet] sent: %s~-1~", buf);
}
#endif
}
示例11: telnet_send_ttype
static void telnet_send_ttype(struct session *ses)
{
char nego[128];
const char *ttype;
switch (ses->last_term_type++)
{
case 0:
ttype=TERM;
break;
case 1:
ttype="hardcopy";
break;
case 2:
ttype="unknown";
break;
/* contrary to what zMud does, we cannot claim we're "vt100" or "ansi", */
/* as we obviously lack an addressable cursor */
default:
ses->last_term_type=0;
case 3:
ttype="KBtin-"VERSION;
}
write_socket(ses, nego,
sprintf(nego, "%c%c%c%c%s%c%c", IAC, SB,
TERMINAL_TYPE, IS, ttype, IAC, SE));
#ifdef TELNET_DEBUG
tintin_printf(ses, "~8~[telnet] sent: IAC SB TERMINAL-TYPE IS \"%s\" IAC SE~-1~", ttype);
#endif
}
示例12: send_request
int
send_request(Request req)
{
if (! req->socket ) {
req->socket = connect_socket(req->host,req->port,0);
if (! req->socket) {
error("Failed to connect to %s:%i\n",req->host,req->port);
return 0;
}
add_req_socket(req->socket->fd);
return 0;
}
if (req->length < 0) {
str cmd = _("%s %s HTTP/1.1\r\n",req->method,req->path);
write_socket(req->socket,cmd);
request_headers(req,_("Host"),req->host);
send_headers(req->socket,req->headers);
req->length = outbound_content_length(req->contents,req->raw_contents);
return req->contents != NULL || req->raw_contents != NULL ;
}
req->written += req->contents ?
send_contents(req->socket,req->contents,is_chunked(req->headers)) :
req->raw_contents ?
send_raw_contents(req->socket,req->raw_contents,req->written,0):
0;
if (is_chunked(req->headers) && req->written >= req->length)
write_chunk(req->socket,NULL,0);
return req->written < req->length;
}
示例13: vprintln_socket
int
vprintln_socket(NDB_SOCKET_TYPE socket, int timeout_millis,
const char * fmt, va_list ap){
char buf[1000];
char *buf2 = buf;
size_t size;
if (fmt != 0 && fmt[0] != 0) {
size = BaseString::vsnprintf(buf, sizeof(buf), fmt, ap)+1;// extra byte for '/n'
/* Check if the output was truncated */
if(size > sizeof(buf)) {
buf2 = (char *)malloc(size);
if(buf2 == NULL)
return -1;
BaseString::vsnprintf(buf2, size, fmt, ap);
}
} else {
size = 1;
}
buf2[size-1]='\n';
int ret = write_socket(socket, timeout_millis, buf2, size);
if(buf2 != buf)
free(buf2);
return ret;
}
示例14: cli_send_smb
BOOL cli_send_smb(struct cli_state *cli)
{
size_t len;
size_t nwritten=0;
ssize_t ret;
/* fd == -1 causes segfaults -- Tom ([email protected]) */
if (cli->fd == -1)
return False;
len = smb_len(cli->outbuf) + 4;
while (nwritten < len) {
ret = write_socket(cli->fd,cli->outbuf+nwritten,len - nwritten);
if (ret <= 0) {
close(cli->fd);
cli->fd = -1;
cli->smb_rw_error = WRITE_ERROR;
DEBUG(0,("Error writing %d bytes to client. %d (%s)\n",
(int)len,(int)ret, strerror(errno) ));
return False;
}
nwritten += ret;
}
return True;
}
示例15: write_socket_len
inline int write_socket_len(int fd, const char* buf)
{
int len;
len = strlen(buf);
if (write_socket(fd, buf, len) < len)
return 0;
return 1;
}