示例#1
0
文件: channels.c 项目: vap0r/wraith
/* Completely removes a channel.
 *
 * This includes the removal of all channel-bans, -exempts and -invites, as
 * well as all user flags related to the channel.
 */
void remove_channel(struct chanset_t *chan)
{
   if (chan != chanset_default) {
     irc_log(chan, "Parting");
     /* Remove the channel from the list, so that noone can pull it
        away from under our feet during the check_part() call. */
     chanset_unlink(chan);

    /* Using chan->name is important here, especially for !chans <cybah> */
    if (!conf.bot->hub && shouldjoin(chan) && chan->name[0])
      dprintf(DP_SERVER, "PART %s\n", chan->name);

     clear_channel(chan, 0);
     noshare = 1;
     /* Remove channel-bans */
     while (chan->bans)
       u_delmask('b', chan, chan->bans->mask, 1);
     /* Remove channel-exempts */
     while (chan->exempts)
       u_delmask('e', chan, chan->exempts->mask, 1);
     /* Remove channel-invites */
     while (chan->invites)
       u_delmask('I', chan, chan->invites->mask, 1);
     /* Remove channel specific user flags */
     user_del_chan(chan->dname);
     noshare = 0;
   }
   free(chan->channel.key);
   if (chan->key)
     free(chan->key);
   if (chan->rmkey)
     free(chan->rmkey);
   free(chan);
}
示例#2
0
/* Completely removes a channel.
 *
 * This includes the removal of all channel-bans, -exempts and -invites, as
 * well as all user flags related to the channel.
 */
static void remove_channel(struct chanset_t *chan)
{
  int i;
  module_entry *me;

  /* Remove the channel from the list, so that noone can pull it
   * away from under our feet during the check_tcl_part() call. */
  (void) chanset_unlink(chan);

  if ((me = module_find("irc", 1, 3)) != NULL)
    (me->funcs[IRC_DO_CHANNEL_PART]) (chan);

  clear_channel(chan, 0);
  noshare = 1;
  /* Remove channel-bans */
  while (chan->bans)
    u_delban(chan, chan->bans->mask, 1);
  /* Remove channel-exempts */
  while (chan->exempts)
    u_delexempt(chan, chan->exempts->mask, 1);
  /* Remove channel-invites */
  while (chan->invites)
    u_delinvite(chan, chan->invites->mask, 1);
  /* Remove channel specific user flags */
  user_del_chan(chan->dname);
  noshare = 0;
  nfree(chan->channel.key);
  for (i = 0; i < MODES_PER_LINE_MAX && chan->cmode[i].op; i++)
    nfree(chan->cmode[i].op);
  if (chan->key)
    nfree(chan->key);
  if (chan->rmkey)
    nfree(chan->rmkey);
  nfree(chan);
}
示例#3
0
// It should always return 0.
gint shutdown_socket_server(gpointer data)
{
#ifdef DETAIL
	g_debug("! Launch shutdown_socket_server() to shutdown the LilyTerm socket server!");
#endif
	if (main_channel) clear_channel(main_channel, TRUE);
	if (address.sun_path) unlink(address.sun_path);
	return 0;
}
示例#4
0
文件: sound.cpp 项目: meesokim/fc-100
void SOUND::process_cmd()
{
	if(params[0] == 0x00) {
		// note off
		clear_channel(&tone);
		clear_channel(&noise);
		clear_channel(&square1);
		clear_channel(&square2);
		clear_channel(&square3);
	}
	else if(params[0] == 0x01) {
		// noise & square
		noise.timbre = params[1] >> 5;
		noise.period = params[2] << 8;
		noise.volume = (MAX_NOISE * (params[3] > 0x1f ? 0x1f : params[3])) / 0x1f;
		noise.output = (noise_table[noise.ptr] * noise.volume) >> 8;
		
		square1.period = params[4] << 8;
		square1.volume = (MAX_SQUARE * (params[7] > 0x7f ? 0x7f : params[7])) / 0x7f;
		square1.output = (square_table[square1.ptr] * square1.volume) >> 8;
		
		square2.period = params[5] << 8;
		square2.volume = (MAX_SQUARE * (params[8] > 0x7f ? 0x7f : params[8])) / 0x7f;
		square2.output = (square_table[square2.ptr] * square2.volume) >> 8;
		
		square3.period = params[6] << 8;
		square3.volume = (MAX_SQUARE * (params[9] > 0x7f ? 0x7f : params[9])) / 0x7f;
		square3.output = (square_table[square3.ptr] * square3.volume) >> 8;
		
		// tone off
		clear_channel(&tone);
	}
示例#5
0
void Player_V2CMS::stopAllSounds() {
	Common::StackLock lock(_mutex);

	for (int i = 0; i < 4; i++) {
		clear_channel(i);
	}
	_next_nr = _current_nr = 0;
	_next_data = _current_data = 0;
	_midiData = 0;
	_midiSongBegin = 0;
	_midiDelay = 0;
	_musicTimer = _musicTimerTicks = 0;
	offAllChannels();
}
示例#6
0
void
inbound_upart (server *serv, char *chan, char *ip, char *reason)
{
	session *sess = find_channel (serv, chan);
	if (sess)
	{
		if (*reason)
			EMIT_SIGNAL (XP_TE_UPARTREASON, sess, serv->nick, ip, chan, reason,
							 0);
		else
			EMIT_SIGNAL (XP_TE_UPART, sess, serv->nick, ip, chan, NULL, 0);
		clear_channel (sess);
	}
}
示例#7
0
文件: inbound.c 项目: TheWug/hexchat
void
inbound_upart (server *serv, char *chan, char *ip, char *reason,
					const message_tags_data *tags_data)
{
	session *sess = find_channel (serv, chan);
	if (sess)
	{
		if (*reason)
			EMIT_SIGNAL_TIMESTAMP (XP_TE_UPARTREASON, sess, tags_data->timestamp, serv->nick, ip, chan, reason);
		else
			EMIT_SIGNAL_TIMESTAMP (XP_TE_UPART, sess, tags_data->timestamp, serv->nick, ip, chan);
		clear_channel (sess);
	}
}
示例#8
0
文件: pwm_py.c 项目: sert00/RPIO
// python function clear_channel_pulses(int channel)
static PyObject*
py_clear_channel(PyObject *self, PyObject *args)
{
    int channel;

    if (!PyArg_ParseTuple(args, "i", &channel))
        return NULL;

    if (clear_channel(channel) == EXIT_FAILURE)
        return raise_error();

    Py_INCREF(Py_None);
    return Py_None;
}
示例#9
0
void
inbound_ukick (server *serv, char *chan, char *kicker, char *reason)
{
	session *sess = find_channel (serv, chan);
	if (sess)
	{
		EMIT_SIGNAL (XP_TE_UKICK, sess, serv->nick, chan, kicker, reason, 0);
		clear_channel (sess);
		if (prefs.hex_irc_auto_rejoin)
		{
			serv->p_join (serv, chan, sess->channelkey);
			safe_strcpy (sess->waitchannel, chan, CHANLEN);
		}
	}
}
示例#10
0
文件: irc.c 项目: Estella/eggdrop-1.8
/* Reset channel information.
 */
static void reset_chan_info(struct chanset_t *chan, int reset)
{
    char beI[4] = "\0";
    /* Leave the channel if we aren't supposed to be there */
    if (channel_inactive(chan)) {
        dprintf(DP_MODE, "PART %s\n", chan->name);
        return;
    }

    /* Don't reset the channel if we're already resetting it */
    if (channel_pending(chan))
        return;

    clear_channel(chan, reset);
    if ((reset & CHAN_RESETBANS) && !(chan->status & CHAN_ASKEDBANS)) {
        chan->status |= CHAN_ASKEDBANS;
        strcat(beI, "b");
    }
    if ((reset & CHAN_RESETEXEMPTS) &&
            !(chan->ircnet_status & CHAN_ASKED_EXEMPTS) && (use_exempts == 1)) {
        chan->ircnet_status |= CHAN_ASKED_EXEMPTS;
        strcat(beI, "e");
    }
    if ((reset & CHAN_RESETINVITED) &&
            !(chan->ircnet_status & CHAN_ASKED_INVITED) && (use_invites == 1)) {
        chan->ircnet_status |= CHAN_ASKED_INVITED;
        strcat(beI, "I");
    }
    if (beI[0])
        dprintf(DP_MODE, "MODE %s +%s\n", chan->name, beI);
    if (reset & CHAN_RESETMODES) {
        /* done here to keep expmem happy, as this is accounted in
           irc.mod, not channels.mod where clear_channel() resides */
        nfree(chan->channel.key);
        chan->channel.key = (char *) channel_malloc (1);
        chan->channel.key[0] = 0;
        chan->status &= ~CHAN_ASKEDMODES;
        dprintf(DP_MODE, "MODE %s\n", chan->name);
    }
    if (reset & CHAN_RESETWHO) {
        chan->status |= CHAN_PEND;
        chan->status &= ~CHAN_ACTIVE;
        refresh_who_chan(chan->name);
    }
    if (reset & CHAN_RESETTOPIC)
        dprintf(DP_MODE, "TOPIC %s\n", chan->name);
}
示例#11
0
文件: inbound.c 项目: TheWug/hexchat
void
inbound_ukick (server *serv, char *chan, char *kicker, char *reason,
					const message_tags_data *tags_data)
{
	session *sess = find_channel (serv, chan);
	if (sess)
	{
		EMIT_SIGNAL_TIMESTAMP (XP_TE_UKICK, sess, tags_data->timestamp, serv->nick, chan, kicker, 
									  reason);
		clear_channel (sess);
		if (prefs.hex_irc_auto_rejoin)
		{
			serv->p_join (serv, chan, sess->channelkey);
			safe_strcpy (sess->waitchannel, chan, CHANLEN);
		}
	}
}
示例#12
0
/* Completely removes a channel.
 * This includes the removal of all channel-bans, -exempts and -invites, as
 * well as all user flags related to the channel.
 */
static void remove_channel(struct chanset_t *chan)
{
   clear_channel(chan, 0);
   noshare = 1;
   /* Remove channel-bans */
   while (chan->bans)
     u_delban(chan, chan->bans->mask, 1);
   /* Remove channel-exempts */
   while (chan->exempts)
     u_delexempt(chan, chan->exempts->mask, 1);
   /* Remove channel-invites */
   while (chan->invites)
     u_delinvite(chan, chan->invites->mask, 1);
   /* Remove channel specific user flags */
   user_del_chan(chan->name);
   noshare = 0;
   killchanset(chan);
}
示例#13
0
static void
scale_channels(const stp_vars_t *v, unsigned *zero_mask)
{
  stpi_channel_group_t *cg = get_channel_group(v);
  int i, j;
  int physical_channel = 0;
  if (!cg)
    return;
  if (zero_mask)
    *zero_mask = 0;
  for (i = 0; i < cg->channel_count; i++)
    {
      stpi_channel_t *ch = &(cg->c[i]);
      if (ch->subchannel_count > 0)
	for (j = 0; j < ch->subchannel_count; j++)
	  {
	    if (cg->gloss_channel != i)
	      {
		stpi_subchannel_t *sch = &(ch->sc[j]);
		unsigned density = sch->s_density;
		unsigned short *output = cg->output_data + physical_channel;
		if (density == 0)
		  {
		    clear_channel(output, cg->width, cg->total_channels);
		    if (zero_mask)
		      *zero_mask |= 1 << physical_channel;
		  }
		else if (density != 65535)
		  {
		    if (scale_channel(output, cg->width, cg->total_channels,
				      density) == 0)
		      if (zero_mask)
			*zero_mask |= 1 << physical_channel;
		  }
		else if (zero_mask)
		  {
		    if (scan_channel(output, cg->width, cg->total_channels)==0)
		      *zero_mask |= 1 << physical_channel;
		  }
	      }
	    physical_channel++;
	  }
    }
}
示例#14
0
文件: sound.cpp 项目: meesokim/fc-100
void SOUND::reset()
{
	clear_channel(&tone);
	clear_channel(&noise);
	clear_channel(&square1);
	clear_channel(&square2);
	clear_channel(&square3);
	clear_channel(&pcm);
	
	memset(params, 0, sizeof(params));
	param_cnt = param_ptr = 0;
	register_id = -1;
	cmd_addr = 0;
}
示例#15
0
文件: irc.c 项目: Estella/eggdrop-1.8
static char *irc_close()
{
    struct chanset_t *chan;

    /* Force bot to part all channels */
    dprintf(DP_MODE, "JOIN 0\n");

    for (chan = chanset; chan; chan = chan->next)
        clear_channel(chan, 1);
    del_bind_table(H_topc);
    del_bind_table(H_splt);
    del_bind_table(H_sign);
    del_bind_table(H_rejn);
    del_bind_table(H_part);
    del_bind_table(H_nick);
    del_bind_table(H_mode);
    del_bind_table(H_kick);
    del_bind_table(H_join);
    del_bind_table(H_pubm);
    del_bind_table(H_pub);
    del_bind_table(H_need);
    rem_tcl_strings(mystrings);
    rem_tcl_ints(myints);
    rem_builtins(H_dcc, irc_dcc);
    rem_builtins(H_msg, C_msg);
    rem_builtins(H_raw, irc_raw);
    rem_tcl_commands(tclchan_cmds);
    rem_help_reference("irc.help");
    del_hook(HOOK_MINUTELY, (Function) check_expired_chanstuff);
    del_hook(HOOK_5MINUTELY, (Function) status_log);
    del_hook(HOOK_ADD_MODE, (Function) real_add_mode);
    del_hook(HOOK_IDLE, (Function) flush_modes);
    Tcl_UntraceVar(interp, "rfc-compliant",
                   TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS,
                   traced_rfccompliant, NULL);
    Tcl_UntraceVar(interp, "net-type",
                   TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS,
                   traced_nettype, NULL);
    module_undepend(MODULE_NAME);
    return NULL;
}
示例#16
0
文件: sound.cpp 项目: meesokim/fc-100
void SOUND::write_io8(uint32 addr, uint32 data)
{
	// PC3 : L->H
	if(data & 0x08) {
		// note off
		clear_channel(&tone);
		clear_channel(&noise);
		clear_channel(&square1);
		clear_channel(&square2);
		clear_channel(&square3);
		
		if(cmd_addr == 0x8402) {
			// y2 monster land
			bool pause = (get_cpu_pc(0) == 0x96c);
			if(pause || !(params[0] == 0x1f && param_ptr > 5)) {
				// terminate command
				if(register_id != -1) {
					cancel_event(register_id);
				}
				memset(params, 0, sizeof(params));
				param_cnt = param_ptr = 0;
				
				// terminate pcm when pause
				if(pause) {
					clear_channel(&pcm);
				}
			}
//			else if(register_id == -1) {
//				vm->register_callback(this, 0, 100, false, &register_id);
//			}
		}
		else {
			if(params[0]) {
				// terminate command
				memset(params, 0, sizeof(params));
				param_cnt = param_ptr = 0;
//				clear_channel(&pcm);
			}
//			if(register_id == -1) {
//				vm->register_callback(this, 0, 100, false, &register_id);
//			}
		}
#ifdef SOUND_DEBUG
		emu->out_debug("PC3\n");
#endif
	}
}
示例#17
0
void Player_V2CMS::stopSound(int nr) {
	Common::StackLock lock(_mutex);

	if (_next_nr == nr) {
		_next_nr = 0;
		_next_data = 0;
	}
	if (_current_nr == nr) {
		for (int i = 0; i < 4; i++) {
			clear_channel(i);
		}
		_current_nr = 0;
		_current_data = 0;
		chainNextSound();
	}
	if (_loadedMidiSong == nr) {
		_midiData = 0;
		_midiSongBegin = 0;
		_midiDelay = 0;
		offAllChannels();
	}
}
示例#18
0
// it will return TRUE if succeed
gboolean read_socket(GIOChannel *channel, GIOCondition condition, gpointer user_data)
{
#ifdef DETAIL
	g_debug("! Launch read_socket() to read data !");
#endif
#ifdef SAFEMODE
	if (channel==NULL) return FALSE;
#endif

	GError *error = NULL;
	gchar *data = NULL, **datas;
	gsize len = 0;
	gsize term;

	if (g_io_channel_read_line (channel, &data, &len, &term, &error) == G_IO_STATUS_ERROR)
		return socket_fault(7, error, channel, TRUE);
	// g_debug("Read %ld bytes from Lilyterm socket: '%s'", len, data);
	if (len > 0)
	{
		//	     0			 1     2	   3	    4		5   6	 7		   8		9	      10      11
		// get data: SOCKET_DATA_VERSION SHELL LOCALE_LIST ENCODING LC_MESSAGES PWD HOME VTE_CJK_WIDTH_STR wmclass_name wmclass_class ENVIRON ARGV
		// clear '\n' at the end of data[]
		data[len-1] = 0;

		datas = split_string(data, "\x10", 12);
		// g_debug("The SOCKET_DATA_VERSION = %s ,and the data sent via socket is %s",
		//	   SOCKET_DATA_VERSION, datas[0]);

		if (datas==NULL)
		{
			// A dirty hack for sometimes the received socket datas is empty.
			socket_fault(14, NULL, NULL, FALSE);
			new_window(0,
				   NULL,
				   NULL,
				   NULL,
				   NULL,
				   NULL,
				   NULL,
				   NULL,
				   FALSE,
				   NULL,
				   NULL,
				   NULL,
				   NULL,
				   FALSE,
				   NULL,
				   NULL,
				   NULL);
		}
		else if (compare_strings(SOCKET_DATA_VERSION, datas[0], TRUE))
		{
			// The SOCKET_DATA_VERSION != the data sent via socket
			gchar *received_socket_version = NULL;
			if (datas) received_socket_version = datas[0];

			gchar *message = g_strdup_printf(_("The data got from socket seems incorrect.\n\n"
							   "\tReceived socket version: %s\n"
							   "\tExpected socket version: %s\n\n"
							   "If you just updated %s recently,\n"
							   "Please close all the windows of %s and try again."),
							   received_socket_version, SOCKET_DATA_VERSION,
							   PACKAGE, PACKAGE);
			error_dialog(NULL,
				     _("The format of socket data is out of date"),
				     "The format of socket data is out of date",
				     GTK_FAKE_STOCK_DIALOG_ERROR,
				     message,
				     NULL);
			g_free(message);
		}
		else
		{
			gchar **argv = split_string(datas[11], "\x10", -1);
			gint argc = 0;
			if (argv)
				while (argv[argc])
					argc ++;

			// g_debug("Final:");
			// g_debug("\targc =%d", argc);
			// print_array("\targv", argv);
			// g_debug("\tSHELL = %s", datas[1]);
			// g_debug("\tenvironments = %s", datas[10]);
			// g_debug("\tlocale_list = %s", datas[2]);
			// g_debug("\tPWD = %s", datas[5]);
			// g_debug("\tHOME = %s", datas[6]);
			// g_debug("\tVTE_CJK_WIDTH_STR = %s", datas[7]);
			// g_debug("\twmclass_name = %s", datas[8]);
			// g_debug("\twmclass_class= %s", datas[9]);
			// g_debug("\tencoding = %s", datas[3]);
			// g_debug("\tlc_messages = %s", datas[4]);

			//GtkNotebook *new_window(int argc,
			//			char *argv[],
			//			gchar *shell,					// 1
			//			gchar *environment,				// 10
			//			gchar *locale_list,				// 2
			//			gchar *PWD,					// 5
			//			gchar *HOME,					// 6
			//			gchar *VTE_CJK_WIDTH_STR,			// 7
			//			gboolean VTE_CJK_WIDTH_STR_overwrite_profile,
			//			gchar *wmclass_name,				// 8
			//			gchar *wmclass_class,				// 9
			//			gchar *user_environ,
			//			gchar *encoding,				// 3
			//			gboolean encoding_overwrite_profile,
			//			gchar *lc_messages,				// 4
			//			struct Window *win_data_orig,
			//			struct Page *page_data_orig)

			new_window(argc,
				   argv,
				   datas[1],
				   datas[10],
				   datas[2],
				   datas[5],
				   datas[6],
				   datas[7],
				   FALSE,
				   datas[8],
				   datas[9],
				   NULL,
				   datas[3],
				   FALSE,
				   datas[4],
				   NULL,
				   NULL);
			g_strfreev(argv);
		}
		g_strfreev(datas);
		data[len-1] = '\n';
		g_free(data);
	}
	clear_channel(channel, TRUE);
	// return FALSE means this connection is finish.
	return FALSE;
}
示例#19
0
// it will return TRUE if scucceed
gboolean send_socket( int   argc,
		      char *argv[],
		      gboolean wait)
{
#ifdef DETAIL
	g_debug("! Launch send_socket() to send data to the exiting LilyTerm !");
	g_debug("! send_socket() argc = %d, wait = %d", argc, wait);
	print_array("! send_socket() argv", argv);
#endif

	GError *error = NULL;
	gsize len;
	extern gchar **environ;

	gchar *locale_list = get_locale_list();

	const gchar *VTE_CJK_WIDTH_STR = g_getenv("VTE_CJK_WIDTH");
	// VTE_CJK_WIDTH can't = NULL
	if (VTE_CJK_WIDTH_STR == NULL) VTE_CJK_WIDTH_STR = "";

	// g_debug("Got LOCALE = %s in send_socket...", get_encoding_from_locale(NULL));
	gchar *encoding = get_encoding_from_locale(NULL);
	if (! compare_strings(encoding, "ANSI_X3.4-1968", TRUE))
	{
		g_free(encoding);
		encoding = g_strdup("UTF-8");
	}
	// g_debug("Got encoding = %s in send_socket...", encoding);
	gchar *lc_messages = g_strdup(get_default_lc_data(LC_MESSAGES));

	gchar *environ_str = convert_array_to_string(environ, '\t');
	// print_array("! send_socket() environ", environ);
	// g_debug("environ_str = %s", environ_str);
	gchar *argv_str = convert_array_to_string(argv, '\x10');
#ifdef SAFEMODE
	gboolean need_free_argv_str = TRUE;
	if (argv_str==NULL) argv_str=g_strdup("");
	if (argv_str==NULL)
	{
		need_free_argv_str = FALSE;
		argv_str = "";
	}
#endif
	// g_debug("argv_str = %s", argv_str);

	// g_debug("SEND DATA: SOCKET_DATA_VERSION = %s", SOCKET_DATA_VERSION);
	// g_debug("SEND DATA: locale_list = %s", locale_list);
	// g_debug("SEND DATA: encoding = %s", encoding);
	// g_debug("SEND DATA: PWD = %s", PWD);
	// g_debug("SEND DATA: VTE_CJK_WIDTH_STR = %s", VTE_CJK_WIDTH_STR);
	// g_debug("SEND DATA: wmclass_name = %s", wmclass_name);
	// g_debug("SEND DATA: wmclass_class = %s", wmclass_class);
	// g_debug("SEND DATA: environ_str = %s", environ_str);
	// g_debug("SEND DATA: argv_str = %s", argv_str);
	//	      0			  1	2	    3	     4		 5   6	  7		    8		 9	       10      11
	// send data: SOCKET_DATA_VERSION SHELL LOCALE_LIST ENCODING LC_MESSAGES PWD HOME VTE_CJK_WIDTH_STR wmclass_name wmclass_class ENVIRON ARGV
	//				  0	1     2	    3	  4	5     6	    7	  8	9     10    11
	gchar *arg_str = g_strdup_printf("%s\x10%s\x10%s\x10%s\x10%s\x10%s\x10%s\x10%s\x10%s\x10%s\x10%s\x10%s\x10",
					 SOCKET_DATA_VERSION,
					 shell,
					 locale_list,
					 encoding,
					 lc_messages,
					 pwd,
					 home,
					 VTE_CJK_WIDTH_STR,
					 wmclass_name,
					 wmclass_class,
					 environ_str,
					 argv_str);
	// g_debug("arg_str = %s", arg_str);
	g_free(locale_list);
	g_free(encoding);
	g_free(lc_messages);
	g_free(environ_str);
#ifdef SAFEMODE
	if (need_free_argv_str)
#endif
		g_free(argv_str);

	// write data!
#ifdef SAFEMODE
	if (fcntl(socket_fd, F_GETFL) < 0) return FALSE;
#endif
	GIOChannel *channel = g_io_channel_unix_new(socket_fd);
	// main_channel is NULL, so that we don't need to launch clear_channel()
	if (!channel) return socket_fault(12, NULL, NULL, FALSE);
	// set the channel to read binary file
	if (g_io_channel_set_encoding(channel, NULL, &error) == G_IO_STATUS_ERROR)
		return socket_fault(9, error, channel, TRUE);
	g_io_channel_set_buffered (channel, FALSE);

#ifdef SAFEMODE
	if ((arg_str == NULL) ||
	    (g_io_channel_write_chars(channel, arg_str, -1, &len, &error)==G_IO_STATUS_ERROR))
#else
	if (g_io_channel_write_chars(channel, arg_str, -1, &len, &error)==G_IO_STATUS_ERROR)
#endif
		// main_channel is NULL, so that we don't need to launch clear_channel()
		return socket_fault(11, error, channel, TRUE);
	// flush writing datas
	if (g_io_channel_flush(channel, &error) == G_IO_STATUS_ERROR)
		// main_channel is NULL, so that we don't need to launch clear_channel()
		return socket_fault(13, error, channel, TRUE);

	g_free(arg_str);

	// So far so good. shutdown and clear channel!
	clear_channel(channel, TRUE);

	// FIXME: sleep for 1 sec to wait the socket server. any better idea?
	if (wait) sleep(1);

	return TRUE;
}
示例#20
0
// it will always return FALSE
gboolean socket_fault(int type, GError *error, GIOChannel *channel, gboolean unref)
{
#ifdef DETAIL
	g_debug("! Launch socket_fault() to show the error message !");
#endif
#ifdef UNIT_TEST
#  define G_WARNING g_message
#else
#  define G_WARNING g_warning
#endif
	switch (type)
	{
		case 1:
			G_WARNING("Error when create %s socket(%s): %s",
				  PACKAGE, address.sun_path, g_strerror (errno));
			break;
		case 2:
			g_message("Can NOT connect to a existing %s socket!", PACKAGE);
			break;
		case 3:
			G_WARNING("Can NOT bind on the socket!");
			break;
		case 4:
			G_WARNING("Can NOT listen on the socket!");
			break;
		case 5:
			G_WARNING("Can not watch on the socket!");
			break;
		case 6:
			G_WARNING("Error when accepting client request via socket!");
			break;
		case 7:
			G_WARNING("Error when reading the data client sent via socket!");
			break;
		case 8:
			G_WARNING("Error when running fcntl command on socket!");
			break;
		case 9:
#ifdef SAFEMODE
			if (error)
#endif
				G_WARNING("Error when setting the encoding of channel: %s", error->message);
			break;
		case 10:
#ifdef SAFEMODE
			if (error)
#endif
				G_WARNING("Error when shutdowning a channel: %s", error->message);
			break;
		case 11:
#ifdef SAFEMODE
			if (error)
#endif
				G_WARNING("Error when writing data to the channel: %s", error->message);
			break;
		case 12:
			G_WARNING("Can NOT create a channel for this socket");
			break;
		case 13:
#ifdef SAFEMODE
			if (error)
#endif
				G_WARNING("Error when flushing the write buffer for the channel: %s", error->message);
			break;
		case 14:
			G_WARNING("Got a NULL string from the socket!");
			break;
		default:
#ifdef FATAL
			print_switch_out_of_range_error_dialog("socket_fault", "type", type);
#endif
			break;
	}
	if (error) g_clear_error (&error);
	clear_channel(channel, unref);
#ifdef UNIT_TEST
#  undef G_WARNING
#endif
	return FALSE;
}