Void T_echo_write (struct bufferevent * bev, void * CTX)
{
Struct evbuffer * output=bufferevent_get_output (bev);
Evbuffer_drain (output, sizeof (output));
If (tempnum==1)//server sends a verification, before I make tempnum to 1 began to send the file data, file fp have in front of open
{
if(! The feof (fp))
{
Memset (sendbuff, 0, sizeof (sendbuff));
The fgets (filebuff, SIZE, fp);
Strcpy_s (sendbuff filebuff);
T_Sendbuff: printf (" % s ", sendbuff);
Evbuffer_add (output, sendbuff, strlen (sendbuff));
Len=evbuffer_get_length (output);
Printf (" evbuffer output length: % d \ n ", len);
}
The else
{
Memset (sendbuff, 0103, 4);
Strcpy (sendbuff, "5, close the file!" );
Evbuffer_add (output, sendbuff, strlen (sendbuff));
Printf (" % s success! \ n ", sendbuff);
Evbuffer_freeze (output, 0);
The fclose (fp);
}
}
}
Server to make the following in the read callback, input data of the obtained evbuffer
Struct evbuffer * output=bufferevent_get_output (bev);
Struct evbuffer * input=bufferevent_get_input (bev);
//evbuffer_expand (input, 1024 * 2);
//remove the input buffer SIZE bytes of data to receivebuff
If (evbuffer_remove (input, receivebuff, SIZE) & lt; 0)
{
Printf (" Evbuffer_remove error! \n");
}
The else
{
Size=size + 1;
Printf (" evbuffer_remove success! \n");
}
Len=strlen (receivebuff);
Printf (" receivebuff len: % d \ n ", len);
Printf (" size1=% d \ n ", size);
//evbuffer_remove (input, receivebuff, SIZE);
////analytical data from the buffer
| receivebuff: printf (" % s \ n ", receivebuff);
CodePudding user response:
This is the code, don't have for years