[Fuse-for-macosx-commits] SF.net SVN: fuse-for-macosx:[713] trunk/fuse
Brought to you by:
fredm
From: <fr...@us...> - 2012-12-05 12:45:09
|
Revision: 713 http://sourceforge.net/p/fuse-for-macosx/code/713 Author: fredm Date: 2012-12-05 12:44:59 +0000 (Wed, 05 Dec 2012) Log Message: ----------- Merge up to vendor revision 4676. Revision Links: -------------- http://sourceforge.net/p/fuse-for-macosx/code/4676 Modified Paths: -------------- trunk/fuse/Makefile.am trunk/fuse/README trunk/fuse/compat/unix/Makefile.am trunk/fuse/compat/unix/file.c trunk/fuse/compat/win32/Makefile.am trunk/fuse/compat.h trunk/fuse/configure.in trunk/fuse/debugger/breakpoint.c trunk/fuse/debugger/command.c trunk/fuse/debugger/debugger.c trunk/fuse/debugger/debugger.h trunk/fuse/debugger/debugger_internals.h trunk/fuse/debugger/event.c trunk/fuse/debugger/expression.c trunk/fuse/debugger/variable.c trunk/fuse/display.c trunk/fuse/display.h trunk/fuse/event.c trunk/fuse/event.h trunk/fuse/fuse.c trunk/fuse/fusepb/English.lproj/InfoPlist.strings trunk/fuse/fusepb/Fuse.xcodeproj/project.pbxproj trunk/fuse/fusepb/Info-Fuse.plist trunk/fuse/fusepb/controllers/FuseController.h trunk/fuse/fusepb/controllers/FuseController.m trunk/fuse/fusepb/controllers/LoadBinaryController.m trunk/fuse/fusepb/controllers/PreferencesController.h trunk/fuse/fusepb/controllers/PreferencesController.m trunk/fuse/fusepb/libspectrum.h trunk/fuse/fusepb/models/Emulator.h trunk/fuse/fusepb/models/Emulator.m trunk/fuse/fusepb/resources/Fuse Help/html/tocstart.html trunk/fuse/fusepb/settings-header.pl trunk/fuse/fusepb/timer/timer.c trunk/fuse/fusepb/views/DisplayOpenGLView.h trunk/fuse/fusepb/views/DisplayOpenGLView.m trunk/fuse/fusepb/xibs/MainMenu.xib trunk/fuse/fusepb/xibs/Preferences.xib trunk/fuse/hacking/ChangeLog trunk/fuse/hacking/Makefile.am trunk/fuse/lib/Makefile.am trunk/fuse/machine.c trunk/fuse/machine.h trunk/fuse/machines/machines_periph.c trunk/fuse/machines/pentagon.c trunk/fuse/machines/pentagon1024.c trunk/fuse/machines/pentagon512.c trunk/fuse/machines/scorpion.c trunk/fuse/machines/spec128.c trunk/fuse/machines/spec16.c trunk/fuse/machines/spec48.c trunk/fuse/machines/spec48_ntsc.c trunk/fuse/machines/spec_se.c trunk/fuse/machines/specplus2.c trunk/fuse/machines/specplus2a.c trunk/fuse/machines/specplus3.c trunk/fuse/machines/specplus3e.c trunk/fuse/machines/tc2048.c trunk/fuse/machines/tc2068.c trunk/fuse/machines/tc2068.h trunk/fuse/machines/ts2068.c trunk/fuse/man/fuse.1 trunk/fuse/memory.c trunk/fuse/memory.h trunk/fuse/mempool.c trunk/fuse/mempool.h trunk/fuse/menu.c trunk/fuse/menu.h trunk/fuse/menu_data.dat trunk/fuse/periph.c trunk/fuse/periph.h trunk/fuse/peripherals/Makefile.am trunk/fuse/peripherals/ay.c trunk/fuse/peripherals/ay.h trunk/fuse/peripherals/dck.c trunk/fuse/peripherals/disk/beta.c trunk/fuse/peripherals/disk/beta.h trunk/fuse/peripherals/disk/disciple.c trunk/fuse/peripherals/disk/disciple.h trunk/fuse/peripherals/disk/disk.c trunk/fuse/peripherals/disk/fdd.c trunk/fuse/peripherals/disk/fdd.h trunk/fuse/peripherals/disk/opus.c trunk/fuse/peripherals/disk/opus.h trunk/fuse/peripherals/disk/plusd.c trunk/fuse/peripherals/disk/plusd.h trunk/fuse/peripherals/disk/upd_fdc.c trunk/fuse/peripherals/disk/upd_fdc.h trunk/fuse/peripherals/disk/wd_fdc.c trunk/fuse/peripherals/disk/wd_fdc.h trunk/fuse/peripherals/fuller.c trunk/fuse/peripherals/fuller.h trunk/fuse/peripherals/ide/divide.c trunk/fuse/peripherals/ide/divide.h trunk/fuse/peripherals/ide/ide.c trunk/fuse/peripherals/ide/ide.h trunk/fuse/peripherals/ide/simpleide.c trunk/fuse/peripherals/ide/simpleide.h trunk/fuse/peripherals/ide/zxatasp.c trunk/fuse/peripherals/ide/zxatasp.h trunk/fuse/peripherals/ide/zxcf.c trunk/fuse/peripherals/ide/zxcf.h trunk/fuse/peripherals/if1.c trunk/fuse/peripherals/if1.h trunk/fuse/peripherals/if2.c trunk/fuse/peripherals/if2.h trunk/fuse/peripherals/kempmouse.c trunk/fuse/peripherals/kempmouse.h trunk/fuse/peripherals/melodik.c trunk/fuse/peripherals/melodik.h trunk/fuse/peripherals/nic/Makefile.am trunk/fuse/peripherals/printer.c trunk/fuse/peripherals/printer.h trunk/fuse/peripherals/scld.c trunk/fuse/peripherals/scld.h trunk/fuse/peripherals/speccyboot.c trunk/fuse/peripherals/speccyboot.h trunk/fuse/peripherals/specdrum.c trunk/fuse/peripherals/specdrum.h trunk/fuse/peripherals/ula.c trunk/fuse/peripherals/ula.h trunk/fuse/pokefinder/pokefinder.c trunk/fuse/pokefinder/pokefinder.h trunk/fuse/pokefinder/pokemem.c trunk/fuse/profile.c trunk/fuse/profile.h trunk/fuse/psg.c trunk/fuse/psg.h trunk/fuse/rzx.c trunk/fuse/rzx.h trunk/fuse/screenshot.c trunk/fuse/screenshot.h trunk/fuse/settings-header.pl trunk/fuse/settings.dat trunk/fuse/settings.pl trunk/fuse/slt.c trunk/fuse/slt.h trunk/fuse/snapshot.c trunk/fuse/sound/aosound.c trunk/fuse/sound/coreaudiosound.c trunk/fuse/sound/sdlsound.c trunk/fuse/sound.c trunk/fuse/sound.h trunk/fuse/spectrum.c trunk/fuse/spectrum.h trunk/fuse/tape.c trunk/fuse/tape.h trunk/fuse/timer/timer.c trunk/fuse/ui/cocoa/options-cocoa-header.pl trunk/fuse/ui/cocoa/options.pl trunk/fuse/ui/gtk/binary.c trunk/fuse/ui/gtk/browse.c trunk/fuse/ui/gtk/confirm.c trunk/fuse/ui/gtk/debugger.c trunk/fuse/ui/gtk/gtkdisplay.c trunk/fuse/ui/gtk/gtkinternals.h trunk/fuse/ui/gtk/gtkjoystick.c trunk/fuse/ui/gtk/gtkmouse.c trunk/fuse/ui/gtk/gtkui.c trunk/fuse/ui/gtk/memory.c trunk/fuse/ui/gtk/options.pl trunk/fuse/ui/gtk/picture.c trunk/fuse/ui/gtk/pokefinder.c trunk/fuse/ui/gtk/pokemem.c trunk/fuse/ui/gtk/rollback.c trunk/fuse/ui/gtk/roms.c trunk/fuse/ui/gtk/stock.c trunk/fuse/ui/options.dat trunk/fuse/ui/scaler/scaler.c trunk/fuse/ui/scaler/scalers.c trunk/fuse/ui/ui.h trunk/fuse/ui/widget/filesel.c trunk/fuse/ui/widget/menu.c trunk/fuse/ui/widget/options.pl trunk/fuse/ui/widget/pokefinder.c trunk/fuse/ui/widget/pokemem.c trunk/fuse/ui/widget/roms.c trunk/fuse/ui/widget/widget.c trunk/fuse/ui/widget/widget.h trunk/fuse/ui/win32/binary.c trunk/fuse/ui/win32/debugger.c trunk/fuse/ui/win32/debugger.rc trunk/fuse/ui/win32/fileselector.c trunk/fuse/ui/win32/memorybrowser.c trunk/fuse/ui/win32/memorybrowser.rc trunk/fuse/ui/win32/options.pl trunk/fuse/ui/win32/picture.c trunk/fuse/ui/win32/pokefinder.c trunk/fuse/ui/win32/roms.c trunk/fuse/ui/win32/win32internals.h trunk/fuse/ui/win32/win32ui.c trunk/fuse/ui/xlib/xdisplay.c trunk/fuse/ui/xlib/xui.c trunk/fuse/ui.c trunk/fuse/unittests/unittests.c trunk/fuse/unittests/unittests.h trunk/fuse/utils.c trunk/fuse/utils.h trunk/fuse/z80/coretest.c trunk/fuse/z80/z80.c trunk/fuse/z80/z80.h trunk/fuse/z80/z80_checks.h trunk/fuse/z80/z80_macros.h trunk/fuse/z80/z80_ops.c Added Paths: ----------- trunk/fuse/compat/unix/socket.c trunk/fuse/compat/win32/socket.c trunk/fuse/data/ trunk/fuse/hacking/peripheral_tests.txt trunk/fuse/hacking/spectranet.txt trunk/fuse/hacking/valgrind.supp trunk/fuse/lib/tests/ trunk/fuse/movie.c trunk/fuse/movie.h trunk/fuse/movie_tables.h trunk/fuse/peripherals/flash/ trunk/fuse/peripherals/nic/w5100.c trunk/fuse/peripherals/nic/w5100.h trunk/fuse/peripherals/nic/w5100_internals.h trunk/fuse/peripherals/nic/w5100_socket.c trunk/fuse/peripherals/spectranet.c trunk/fuse/peripherals/spectranet.h Property Changed: ---------------- trunk/fuse/ Property changes on: trunk/fuse ___________________________________________________________________ Modified: svn:mergeinfo - /vendor/fuse-emulator/0.10.0/fuse:556-557 /vendor/fuse-emulator/0.10.0-pre1/fuse:545-546 /vendor/fuse-emulator/current/fuse:530-685 /vendor/fuse-emulator/fuse-1.0.0a/fuse:668-669 /vendor/fuse-emulator/fuse-r4617/fuse:686 + /vendor/fuse-emulator/0.10.0/fuse:556-557 /vendor/fuse-emulator/0.10.0-pre1/fuse:545-546 /vendor/fuse-emulator/current/fuse:530-712 /vendor/fuse-emulator/fuse-1.0.0a/fuse:668-669 /vendor/fuse-emulator/fuse-r4617/fuse:686 Modified: trunk/fuse/Makefile.am =================================================================== --- trunk/fuse/Makefile.am 2012-11-24 10:24:08 UTC (rev 712) +++ trunk/fuse/Makefile.am 2012-12-05 12:44:59 UTC (rev 713) @@ -1,7 +1,7 @@ # Process this file with automake to produce Makefile.in ## Copyright (c) 1999-2009 Philip Kendall -## $Id: Makefile.am 4288 2011-02-03 21:06:22Z pak21 $ +## $Id: Makefile.am 4674 2012-02-20 11:03:58Z fredm $ ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -26,6 +26,7 @@ bin_PROGRAMS = fuse SUBDIRS = @COMPAT_SUBDIR@ \ + data \ debugger \ hacking \ lib \ @@ -41,7 +42,8 @@ unittests \ z80 -DIST_SUBDIRS = debugger \ +DIST_SUBDIRS = data \ + debugger \ hacking \ lib \ machines \ @@ -66,6 +68,7 @@ memory.c \ mempool.c \ menu.c \ + movie.c \ module.c \ periph.c \ profile.c \ @@ -104,6 +107,7 @@ machines/libmachines.a \ peripherals/libperipherals.a \ peripherals/disk/libdisk.a \ +peripherals/flash/libflash.a \ peripherals/ide/libide.a \ peripherals/nic/libnic.a \ pokefinder/libpokefinder.a \ @@ -128,6 +132,7 @@ machines/libmachines.a \ peripherals/libperipherals.a \ peripherals/disk/libdisk.a \ +peripherals/flash/libflash.a \ peripherals/ide/libide.a \ peripherals/nic/libnic.a \ pokefinder/libpokefinder.a \ @@ -173,6 +178,8 @@ memory.h \ mempool.h \ menu.h \ + movie.h \ + movie_tables.h \ module.h \ periph.h \ psg.h \ Modified: trunk/fuse/README =================================================================== --- trunk/fuse/README 2012-11-24 10:24:08 UTC (rev 712) +++ trunk/fuse/README 2012-12-05 12:44:59 UTC (rev 713) @@ -64,6 +64,8 @@ * Either the native port by Fredrick Meunier, or the original version will compile on OS X 10.3 (Panther) or later. +* On Mac OS X Lion you will need to use clang as gcc-llvm-4.2.1 fails to + correctly compile z80_ops.c. Windows @@ -216,4 +218,4 @@ Philip Kendall <phi...@sh...> 16 December 2010 -$Id: README 4410 2011-05-01 10:51:21Z zubzero $ +$Id: README 4624 2012-01-09 20:59:35Z pak21 $ Modified: trunk/fuse/compat/unix/Makefile.am =================================================================== --- trunk/fuse/compat/unix/Makefile.am 2012-11-24 10:24:08 UTC (rev 712) +++ trunk/fuse/compat/unix/Makefile.am 2012-12-05 12:44:59 UTC (rev 713) @@ -1,7 +1,7 @@ ## Process this file with automake to produce Makefile.in ## Copyright (c) 2007-2008 Philip Kendall -## $Id: Makefile.am 4237 2010-12-31 19:31:26Z pak21 $ +## $Id: Makefile.am 4624 2012-01-09 20:59:35Z pak21 $ ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -31,6 +31,7 @@ file.c \ osname.c \ paths.c \ + socket.c \ timer.c \ tuntap.c Modified: trunk/fuse/compat/unix/file.c =================================================================== --- trunk/fuse/compat/unix/file.c 2012-11-24 10:24:08 UTC (rev 712) +++ trunk/fuse/compat/unix/file.c 2012-12-05 12:44:59 UTC (rev 713) @@ -1,7 +1,7 @@ /* file.c: File-related compatibility routines Copyright (c) 2008 Philip Kendall - $Id: file.c 4534 2011-08-11 12:59:47Z fredm $ + $Id: file.c 4624 2012-01-09 20:59:35Z pak21 $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -64,7 +64,7 @@ if( bytes != file->length ) { ui_error( UI_ERROR_ERROR, "error reading file: expected %lu bytes, but read only %lu", - file->length, bytes ); + (unsigned long)file->length, (unsigned long)bytes ); return 1; } @@ -78,7 +78,7 @@ if( bytes != length ) { ui_error( UI_ERROR_ERROR, "error writing file: expected %lu bytes, but wrote only %lu", - length, bytes ); + (unsigned long)length, (unsigned long)bytes ); return 1; } Copied: trunk/fuse/compat/unix/socket.c (from rev 712, vendor/fuse-emulator/current/fuse/compat/unix/socket.c) =================================================================== --- trunk/fuse/compat/unix/socket.c (rev 0) +++ trunk/fuse/compat/unix/socket.c 2012-12-05 12:44:59 UTC (rev 713) @@ -0,0 +1,118 @@ +/* socket.c: Socket-related compatibility routines + Copyright (c) 2011 Philip Kendall + + $Id$ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + Author contact information: + + E-mail: phi...@sh... + +*/ + +#include <config.h> + +#include <errno.h> +#include <string.h> +#include <unistd.h> + +#include "compat.h" +#include "fuse.h" +#include "ui/ui.h" + +const compat_socket_t compat_socket_invalid = -1; +const int compat_socket_EBADF = EBADF; + +struct compat_socket_selfpipe_t { + int read_fd; + int write_fd; +}; + +void +compat_socket_networking_init( void ) +{ + /* No action necessary */ +} + +void +compat_socket_networking_end( void ) +{ + /* No action necessary */ +} + +int +compat_socket_close( compat_socket_t fd ) +{ + return close( fd ); +} + +int compat_socket_get_error( void ) +{ + return errno; +} + +const char * +compat_socket_get_strerror( void ) +{ + return strerror( errno ); +} + +compat_socket_selfpipe_t* compat_socket_selfpipe_alloc( void ) +{ + int error; + int pipefd[2]; + + compat_socket_selfpipe_t *self = malloc( sizeof( *self ) ); + if( !self ) { + ui_error( UI_ERROR_ERROR, "%s: %d: out of memory", __FILE__, __LINE__ ); + fuse_abort(); + } + + error = pipe( pipefd ); + if( error ) { + ui_error( UI_ERROR_ERROR, "%s: %d: error %d creating pipe", __FILE__, __LINE__, error ); + fuse_abort(); + } + + self->read_fd = pipefd[0]; + self->write_fd = pipefd[1]; + + return self; +} + +void compat_socket_selfpipe_free( compat_socket_selfpipe_t *self ) +{ + close( self->read_fd ); + close( self->write_fd ); + free( self ); +} + +compat_socket_t compat_socket_selfpipe_get_read_fd( compat_socket_selfpipe_t *self ) +{ + return self->read_fd; +} + +void compat_socket_selfpipe_wake( compat_socket_selfpipe_t *self ) +{ + const char dummy = 0; + write( self->write_fd, &dummy, 1 ); +} + +void compat_socket_selfpipe_discard_data( compat_socket_selfpipe_t *self ) +{ + char bitbucket; + read( self->read_fd, &bitbucket, 1 ); +} Modified: trunk/fuse/compat/win32/Makefile.am =================================================================== --- trunk/fuse/compat/win32/Makefile.am 2012-11-24 10:24:08 UTC (rev 712) +++ trunk/fuse/compat/win32/Makefile.am 2012-12-05 12:44:59 UTC (rev 713) @@ -1,7 +1,7 @@ ## Process this file with automake to produce Makefile.in ## Copyright (c) 2007-2008 Philip Kendall -## $Id: Makefile.am 4237 2010-12-31 19:31:26Z pak21 $ +## $Id: Makefile.am 4624 2012-01-09 20:59:35Z pak21 $ ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -31,6 +31,7 @@ ../unix/file.c \ osname.c \ paths.c \ + socket.c \ timer.c \ ../unix/tuntap.c Copied: trunk/fuse/compat/win32/socket.c (from rev 712, vendor/fuse-emulator/current/fuse/compat/win32/socket.c) =================================================================== --- trunk/fuse/compat/win32/socket.c (rev 0) +++ trunk/fuse/compat/win32/socket.c 2012-12-05 12:44:59 UTC (rev 713) @@ -0,0 +1,241 @@ +/* socket.c: Socket-related compatibility routines + Copyright (c) 2011 Sergio Baldoví, Philip Kendall + + $Id$ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + Author contact information: + + E-mail: phi...@sh... + +*/ + +#include <config.h> + +#include <winsock2.h> +#include <ws2tcpip.h> + +#include "compat.h" +#include "fuse.h" +#include "ui/ui.h" + +const compat_socket_t compat_socket_invalid = INVALID_SOCKET; +const int compat_socket_EBADF = WSAENOTSOCK; + +struct compat_socket_selfpipe_t { + SOCKET self_socket; + libspectrum_word port; +}; + +int +compat_socket_close( compat_socket_t fd ) +{ + return closesocket( fd ); +} + +int compat_socket_get_error( void ) +{ + return WSAGetLastError(); +} + +const char * +compat_socket_get_strerror( void ) +{ + static TCHAR buffer[256]; + TCHAR *ptr; + DWORD msg_size; + + /* get description of last winsock error */ + msg_size = FormatMessage( + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, WSAGetLastError(), + MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), + buffer, sizeof( buffer ) / sizeof( TCHAR ), NULL ); + + if( !msg_size ) return NULL; + + /* skip 'new line' like chars */ + for( ptr = buffer; *ptr; ptr++ ) { + if( ( *ptr == '\r' ) || ( *ptr == '\n' ) ) { + *ptr = '\0'; + break; + } + } + + return (const char *)buffer; +} + +static int +selfpipe_test( compat_socket_selfpipe_t *self ) +{ + fd_set readfds; + int active; + struct timeval tv = { 1, 0 }; + + /* Send testing packet */ + compat_socket_selfpipe_wake( self ); + + /* Safe reading from control socket */ + FD_ZERO( &readfds ); + FD_SET( self->self_socket, &readfds ); + active = select( 0, &readfds, NULL, NULL, &tv ); + if( active == 0 || active == compat_socket_invalid ) { + return -1; + } + + /* Discard testing packet */ + if( FD_ISSET( self->self_socket, &readfds ) ) { + compat_socket_selfpipe_discard_data( self ); + } + + return 0; +} + +compat_socket_selfpipe_t * +compat_socket_selfpipe_alloc( void ) +{ + unsigned long mode = 1; + struct sockaddr_in sa; + socklen_t sa_len = sizeof(sa); + + compat_socket_selfpipe_t *self = malloc( sizeof( *self ) ); + if( !self ) { + ui_error( UI_ERROR_ERROR, "%s: %d: out of memory", __FILE__, __LINE__ ); + fuse_abort(); + } + + self->self_socket = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ); + if( self->self_socket == compat_socket_invalid ) { + ui_error( UI_ERROR_ERROR, + "%s: %d: failed to open socket; errno %d: %s\n", + __FILE__, __LINE__, compat_socket_get_error(), + compat_socket_get_strerror() ); + fuse_abort(); + } + + /* Set nonblocking mode */ + if( ioctlsocket( self->self_socket, FIONBIO, &mode ) == -1 ) { + ui_error( UI_ERROR_ERROR, + "%s: %d: failed to set socket nonblocking; errno %d: %s\n", + __FILE__, __LINE__, compat_socket_get_error(), + compat_socket_get_strerror() ); + fuse_abort(); + } + + memset( &sa, 0, sizeof(sa) ); + sa.sin_family = AF_INET; + sa.sin_addr.s_addr = htonl( INADDR_LOOPBACK ); + + if( bind( self->self_socket, (struct sockaddr*)&sa, sizeof(sa) ) == -1 ) { + ui_error( UI_ERROR_ERROR, + "%s: %d: failed to bind socket; errno %d: %s\n", + __FILE__, __LINE__, compat_socket_get_error(), + compat_socket_get_strerror() ); + fuse_abort(); + } + + /* Get ephemeral port number */ + if( getsockname( self->self_socket, (struct sockaddr *)&sa, &sa_len ) == -1 ) { + ui_error( UI_ERROR_ERROR, + "%s: %d: failed to get socket name; errno %d: %s\n", + __FILE__, __LINE__, compat_socket_get_error(), + compat_socket_get_strerror() ); + fuse_abort(); + } + + self->port = ntohs( sa.sin_port ); + + /* Test communications in order to detect blocking firewalls */ + if( selfpipe_test( self ) == -1 ) { + ui_error( UI_ERROR_ERROR, + "Networking: failed to test internal communications" ); + fuse_abort(); + } + + return self; +} + +void +compat_socket_selfpipe_free( compat_socket_selfpipe_t *self ) +{ + compat_socket_close( self->self_socket ); + free( self ); +} + +compat_socket_t +compat_socket_selfpipe_get_read_fd( compat_socket_selfpipe_t *self ) +{ + return self->self_socket; +} + +void +compat_socket_selfpipe_wake( compat_socket_selfpipe_t *self ) +{ + struct sockaddr_in sa; + + memset( &sa, 0, sizeof(sa) ); + sa.sin_family = AF_INET; + sa.sin_addr.s_addr = htonl( INADDR_LOOPBACK ); + sa.sin_port = htons( self->port ); + + sendto( self->self_socket, NULL, 0, 0, (struct sockaddr*)&sa, sizeof(sa) ); +} + +void +compat_socket_selfpipe_discard_data( compat_socket_selfpipe_t *self ) +{ + ssize_t bytes_read; + struct sockaddr_in sa; + socklen_t sa_length = sizeof(sa); + static char bitbucket[0x100]; + + do { + /* Socket is non blocking, so we can do this safely */ + bytes_read = recvfrom( self->self_socket, bitbucket, sizeof( bitbucket ), + 0, (struct sockaddr*)&sa, &sa_length ); + } while( bytes_read != -1 ); +} + + +void +compat_socket_networking_init( void ) +{ + WORD wVersionRequested; + WSADATA wsaData; + int error; + + wVersionRequested = MAKEWORD( 2, 2 ); + error = WSAStartup( wVersionRequested, &wsaData ); + if( error ) { + ui_error( UI_ERROR_ERROR, "%s:%d: error %d from WSAStartup()", __FILE__, + __LINE__, error ); + fuse_abort(); + } + + if( LOBYTE( wsaData.wVersion ) != 2 || HIBYTE( wsaData.wVersion ) != 2 ) { + ui_error( UI_ERROR_ERROR, + "%s:%d: unexpected version 0x%02x from WSAStartup()", + __FILE__, __LINE__, wsaData.wVersion ); + fuse_abort(); + } +} + +void +compat_socket_networking_end( void ) +{ + WSACleanup(); +} + Modified: trunk/fuse/compat.h =================================================================== --- trunk/fuse/compat.h 2012-11-24 10:24:08 UTC (rev 712) +++ trunk/fuse/compat.h 2012-12-05 12:44:59 UTC (rev 713) @@ -1,7 +1,7 @@ /* compat.h: various compatibility bits Copyright (c) 2003-2008 Philip Kendall - $Id: compat.h 4534 2011-08-11 12:59:47Z fredm $ + $Id: compat.h 4648 2012-01-22 19:57:35Z pak21 $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -31,6 +31,10 @@ #include <stdlib.h> #include <sys/types.h> +#ifdef WIN32 +#include <winsock2.h> +#endif + /* Remove the gcc-specific incantations if we're not using gcc */ #ifdef __GNUC__ @@ -120,4 +124,30 @@ int compat_get_tap( const char *interface_name ); +/* Socket handling */ + +#ifndef WIN32 +typedef int c |