• Home
  • Assertions
  • Poetry
  • Programming

Record and Reverie

General things I find interesting

Feed on
Posts
Comments
« New Semester
I finally Quit »

Fixing File Transfer

Feb 24th, 2007 by Graham Booker

I work on Adium from time to time, and it currently has a major issue with file transfer. The problem is that the libgaim code used a particular method to detect if a socket was closed, but this method isn’t reliable since Adium wraps the sockets in CFSockets to detect activity. So, we had to use another method. I elected to take some code from Fire since I solved the same problem there a while back. Here it is for the curious:

/*
 * Taken from Fire's FaimP2PConnection.m:
 * The job of this function is to detect if the connection failed or not
 * There has to be a better way to do this
 *
 * Any socket that fails to connect will select for reading and writing
 * and all reads and writes will fail
 * Any listening socket will select for reading, and any read will fail
 * So, select for writing, if you can write, and the write fails, not connected
 */

{
	fd_set thisfd;
	struct timeval timeout;
	
	FD_ZERO(&thisfd);
	FD_SET(fd, &thisfd);
	timeout.tv_sec = 0;
	timeout.tv_usec = 0;
	select(fd+1, NULL, &thisfd, NULL, &timeout);
	if(FD_ISSET(fd, &thisfd)){
		ssize_t length = 0;
		char buffer[4] = {0, 0, 0, 0};
		
		length = write(fd, buffer, length);
		if(length == -1)
		{
			/* Not connected */
			ret = -1;
			*error = ENOTCONN;
			AILog(@"adium_input_get_error(%i): Socket is NOT valid", fd);
		}
	}
}

Rather hackish, but it does work.

Posted in General

Comments are closed.

  • Recent Posts

    • Google’s Analytics Mistake
    • Switching back to Safari
    • Apple has become the new Microsoft
    • Sapphire Plugin
    • Key Fixed
    • Sometimes you just got to laugh
  • Archives

    2021
    2020
    March 2020 (1)
    2019
    November 2019 (1)
    2018
    June 2018 (1)July 2018 (1)December 2018 (1)
    2017
    January 2017 (2)June 2017 (1)August 2017 (1)
    2016
    June 2016 (1)August 2016 (1)
    2015
    January 2015 (1)February 2015 (1)December 2015 (1)
    2014
    June 2014 (1)July 2014 (1)August 2014 (2)
    2013
    February 2013 (2)March 2013 (1)April 2013 (1)June 2013 (1)November 2013 (1)
    2012
    April 2012 (2)May 2012 (1)June 2012 (1)November 2012 (1)
    2011
    January 2011 (1)October 2011 (1)November 2011 (1)December 2011 (1)
    2010
    February 2010 (2)April 2010 (1)June 2010 (1)July 2010 (1)August 2010 (1)September 2010 (1)October 2010 (2)December 2010 (3)
    2009
    January 2009 (1)February 2009 (1)March 2009 (2)May 2009 (1)July 2009 (3)September 2009 (1)
    2008
    January 2008 (1)February 2008 (4)March 2008 (1)April 2008 (6)May 2008 (1)June 2008 (3)August 2008 (1)September 2008 (2)October 2008 (2)December 2008 (1)
    2007
    January 2007 (1)February 2007 (4)March 2007 (5)April 2007 (4)May 2007 (1)June 2007 (6)August 2007 (3)September 2007 (3)November 2007 (3)December 2007 (4)
    2006
    January 2006 (4)February 2006 (10)March 2006 (4)April 2006 (6)May 2006 (2)June 2006 (4)July 2006 (1)August 2006 (1)September 2006 (4)October 2006 (6)November 2006 (3)December 2006 (3)
    2005
    October 2005 (6)November 2005 (13)December 2005 (1)
    2004
    February 2004 (2)March 2004 (1)April 2004 (1)May 2004 (6)June 2004 (6)July 2004 (3)August 2004 (2)September 2004 (1)November 2004 (5)
    2003
    September 2003 (1)October 2003 (3)November 2003 (1)December 2003 (1)
  • Categories

    • Breakaway (5)
    • Family (4)
    • Friends (2)
    • General (148)
    • Nature Pictures (8)
    • Politics (2)
    • Programming (41)
    • School (11)
    • SysAdmin (8)
    • Teaching (2)
  • Tags

    AC3 Ads Code Frontrow Java Objective-C Open Source Perian Perl permissions plex plugin RSS Sapphire School Servers ZFS

  • Pages

    • Assertions
      • Female Friends Who Won’t Date You
      • Not Dating Friends
    • Poetry
      • Curtis Staying Over
      • Girl Questions
      • Scaring Girls Off
      • Summer’s End
    • Programming
      • Fire Development
      • Kyocera Ringtone Converter for the Mac
      • Perian
      • Text Compression

Record and Reverie © 2021 All Rights Reserved.

WordPress Themes | Web Hosting Bluebook