[gnet] WIN32 weirdness - demo app



using: http://www.gnetlibrary.org/win32/gnet-src-1.1.8-20030126.zip
and http://www.gimp.org/~tml/gimp/win32/glib-2.2.1.zip (+other req'd libraries from tor)

Refined problem description:
   Interaction between gnet_conn_readline (...) and gnet_conn_write(...)
on win32.

If you run the attached application(on win32) and 2 instances of telnet to the port it listens on, typing lines of text into telnet client 1 (tc1) will recieve its own data back fine (echo'd), however telnet client 2 (tc2) will not recieve any data until at least 1 byte is send from tc2 to the party server, when at least 1 byte is recieved(not even a whole line) the entire write queue is dumped to tc2. If no data is sent, the gnet_conn_write timeout will be reached.

This could mean that the underlying read is blocking? and thus no data can be written until something is recieved? I'm not sure where to go about looking for the problem. The gnet source seems to be using glib io watches and such?
App behaves properly on linux.

Any help would be appreciated.

-Adam



/* Echo server
 * Copyright (C) 2000  David Helder
 *
 * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#define GNET_EXPERIMENTAL
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gnet.h>	/* Or <gnet/gnet.h> when installed. */

#include <signal.h>

static void object_echoserver (gint port);
GList *connection_list = NULL;

int
main(int argc, char** argv)
{
  int port = 0;

  gnet_init ();

  if (argc < 2 && argc != 3)
    {
		port=33333;
    }else {
		port = atoi(argv[1]);
	}

  g_print ("Object party line echo server running on %d\n",port);
  object_echoserver(port);
  return 0;

}

/* ************************************************************ */

static void ob_server_func (GServer* server, GServerStatus status,
			    GConn* conn, gpointer user_data);
static gboolean ob_client_func (GConn* conn, GConnStatus status,
				gchar* buffer, gint length,
				gpointer user_data);
static void ob_sig_int (int signum);

static GServer* ob_server = NULL;

void send_to(gpointer data,gpointer user_data){
	struct _GConn* conn = (struct _GConn*) data;
	gchar* buf = (gchar*) user_data;
	gchar* buf2 = g_memdup (buf, strlen(buf)+1);
	gnet_conn_write( conn, buf2, strlen(buf2), 3000);
}

static void
object_echoserver (gint port)
{
  GMainLoop* main_loop;
  GInetAddr* addr;
  GServer* server;

  /* Create the main loop */
  main_loop = g_main_new(FALSE);

  /* Create the interface */
  addr = gnet_inetaddr_new_any ();
  gnet_inetaddr_set_port (addr, port);

  /* Create the server */
  server = gnet_server_new (addr, TRUE, ob_server_func, NULL);
  if (!server)
    {
      fprintf (stderr, "Error: Could not start server\n");
      exit (EXIT_FAILURE);
    }

  ob_server = server;
  signal (SIGINT, ob_sig_int);

  /* Start the main loop */
  g_main_run(main_loop);
}


static void
ob_server_func (GServer* server, GServerStatus status,
		struct _GConn* conn, gpointer user_data)
{
  switch (status)
    {
    case GNET_SERVER_STATUS_CONNECT:
      {
	connection_list = g_list_append( connection_list, conn );
	conn->func = ob_client_func;
	gnet_conn_readline (conn, NULL, 1024, 30000);
	break;
      }

    case GNET_SERVER_STATUS_ERROR:
      {
	gnet_server_delete (server);
	exit (EXIT_FAILURE);
	break;
      }
    }
}


static gboolean
ob_client_func (GConn* conn, GConnStatus status,
		gchar* buffer, gint length, gpointer user_data)
{
  gchar* buf2;
  switch (status)
    {
    case GNET_CONN_STATUS_READ:
      {
	buf2= g_memdup (buffer, length+1);
    buf2[length]='\0';
	//gnet_conn_write (conn, buffer_copy, length, 0);
	g_list_foreach(connection_list,send_to,buf2);
	break;
      }

    case GNET_CONN_STATUS_WRITE:
      {
	g_free (buffer);
	break;
      }

    case GNET_CONN_STATUS_CLOSE:
    case GNET_CONN_STATUS_TIMEOUT:
    case GNET_CONN_STATUS_ERROR:
      {
	gnet_conn_delete (conn, TRUE);
	break;
      }

    default:
      g_assert_not_reached ();
    }

  return TRUE;	/* TRUE means read more if status was read, otherwise
                   its ignored */
}



static void
ob_sig_int (int signum)
{
  gnet_server_delete (ob_server);
  exit (EXIT_FAILURE);
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]