/** * mate_vfs_socket_buffer_destroy: * @socket_buffer: buffered socket to destroy. * @close_socket: if %TRUE, the socket being buffered will be closed. * @cancellation: handle allowing cancellation of the operation. * * Free the socket buffer. * * Return value: #MateVFSResult indicating the success of the operation. */ MateVFSResult mate_vfs_socket_buffer_destroy (MateVFSSocketBuffer *socket_buffer, gboolean close_socket, MateVFSCancellation *cancellation) { mate_vfs_socket_buffer_flush (socket_buffer, cancellation); if (close_socket) { mate_vfs_socket_close (socket_buffer->socket, cancellation); } g_free (socket_buffer); return MATE_VFS_OK; }
int main (int argc, char **argv) { MateVFSResult result = MATE_VFS_OK; gchar buffer[1024]; gchar *host; gint port; MateVFSFileSize bytes_read; MateVFSSSL *ssl = NULL; MateVFSSocket *socket = NULL; MateVFSSocketBuffer *socketbuffer = NULL; if (argc != 3) { printf ("Usage: %s <host> <port>\n", argv[0]); return 1; } host = argv[1]; port = atoi (argv[2]); if (port <= 0) { printf ("Invalid port\n"); return 1; } if (! mate_vfs_init ()) { fprintf (stderr, "Cannot initialize mate-vfs.\n"); return 1; } switch (abstraction) { case SOCKETBUFFER: g_print ("Testing MateVFSSocketBuffer"); case SOCKET: g_print (" and MateVFSSocket"); case SSL: g_print (" and MateVFSSSL"); } g_print (".\n"); result = mate_vfs_ssl_create (&ssl, host, port, NULL); show_result (result, "ssl_create", host, port); if (ssl == NULL) { fprintf (stderr, "couln't connect\n"); return -1; } if (abstraction >= SOCKET) { socket = mate_vfs_ssl_to_socket (ssl); if (socket == NULL) { fprintf (stderr, "couldn't create socket object\n"); return -1; } if (abstraction == SOCKETBUFFER) { socketbuffer = mate_vfs_socket_buffer_new (socket); if (socketbuffer == NULL) { fprintf (stderr, "couldn't create socketbuffer object\n"); return -1; } } } switch (abstraction) { case SSL: result = mate_vfs_ssl_write (ssl, HTTP_REQUEST, strlen(HTTP_REQUEST), &bytes_read, NULL); break; case SOCKET: result = mate_vfs_socket_write (socket, HTTP_REQUEST, strlen(HTTP_REQUEST), &bytes_read, NULL); break; case SOCKETBUFFER: result = mate_vfs_socket_buffer_write (socketbuffer, HTTP_REQUEST, strlen(HTTP_REQUEST), &bytes_read, NULL); mate_vfs_socket_buffer_flush (socketbuffer, NULL); break; } show_result (result, "write", host, port); while( result==MATE_VFS_OK ) { switch (abstraction) { case SSL: result = mate_vfs_ssl_read (ssl, buffer, sizeof buffer - 1, &bytes_read, NULL); break; case SOCKET: result = mate_vfs_socket_read (socket, buffer, sizeof buffer - 1, &bytes_read, NULL); break; case SOCKETBUFFER: result = mate_vfs_socket_buffer_read ( socketbuffer, buffer, sizeof buffer - 1, &bytes_read, NULL); break; } show_result (result, "read", host, port); buffer[bytes_read] = 0; write (1,buffer,bytes_read); if(!bytes_read) break; } switch (abstraction) { case SSL: mate_vfs_ssl_destroy (ssl, NULL); break; case SOCKET: mate_vfs_socket_close (socket, NULL); break; case SOCKETBUFFER: mate_vfs_socket_buffer_destroy (socketbuffer, TRUE, NULL); break; } return 0; }