一段vsftpd的源代码,关于结构体函数
[color=#FF0000]static struct vsf_transfer_ret(struct vsf_session* p_sess, int file_fd, int is_ascii)[/color]/*各位大牛对这种函数形式有了解没?*/{ static char* p_readbuf; static char* p_asciibuf; struct vsf_transfer_ret ret_struct = { 0, 0 }; unsigned int chunk_size = get_chunk_size(); char* p_writefrom_buf; int prev_cr = 0; if (p_readbuf == 0) { vsf_secbuf_alloc(&p_readbuf, VSFTP_DATA_BUFSIZE); } if (is_ascii) { if (p_asciibuf == 0) { /* NOTE!! * 2 factor because we can double the data by doing our ASCII * linefeed mangling */ vsf_secbuf_alloc(&p_asciibuf, VSFTP_DATA_BUFSIZE * 2); } p_writefrom_buf = p_asciibuf; } else { p_writefrom_buf = p_readbuf; } while (1) { unsigned int num_to_write; int retval = vsf_sysutil_read(file_fd, p_readbuf, chunk_size); if (vsf_sysutil_retval_is_error(retval)) { ret_struct.retval = -1; return ret_struct; } else if (retval == 0) { /* Success - cool */ return ret_struct; } if (is_ascii) { struct bin_to_ascii_ret ret = vsf_ascii_bin_to_ascii(p_readbuf, p_asciibuf, (unsigned int) retval, prev_cr); num_to_write = ret.stored; prev_cr = ret.last_was_cr; } else { num_to_write = (unsigned int) retval; } retval = ftp_write_data(p_sess, p_writefrom_buf, num_to_write); if (!vsf_sysutil_retval_is_error(retval)) { ret_struct.transferred += (unsigned int) retval; } if (vsf_sysutil_retval_is_error(retval) || (unsigned int) retval != num_to_write) { ret_struct.retval = -2; return ret_struct; } }}static struct vsf_transfer_retdo_file_send_sendfile(struct vsf_session* p_sess, int net_fd, int file_fd, filesize_t curr_file_offset, filesize_t bytes_to_send){ int retval; unsigned int chunk_size = 0; struct vsf_transfer_ret ret_struct = { 0, 0 }; filesize_t init_file_offset = curr_file_offset; filesize_t bytes_sent; if (p_sess->bw_rate_max) { chunk_size = get_chunk_size(); } /* Just because I can ;-) */ retval = vsf_sysutil_sendfile(net_fd, file_fd, &curr_file_offset, bytes_to_send, chunk_size); bytes_sent = curr_file_offset - init_file_offset; ret_struct.transferred = bytes_sent; if (vsf_sysutil_retval_is_error(retval)) { ret_struct.retval = -2; return ret_struct; } else if (bytes_sent != bytes_to_send) { ret_struct.retval = -2; return ret_struct; } return ret_struct; }