⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ipmsg.c

📁 linux下的飞鸽传书 日本人设计 使用非常方便
💻 C
字号:
/* * Initial main.c file generated by Glade. Edit as required. * Glade will not overwrite this file. */#ifdef HAVE_CONFIG_H#  include <config.h>#endif#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#include <errno.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <sys/file.h>#include <syslog.h>#include <gnome.h>#include <glib.h>#include <panel-applet.h>#include "interface.h"#include "support.h"#include "common.h"#define GLADE_HOOKUP_OBJECT(component,widget,name) \  g_object_set_data_full (G_OBJECT (component), name, \    gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref)#define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \  g_object_set_data (G_OBJECT (component), name, widget)gint target_tag;udp_con_t *udp_con;static udp_con_t con;voidread_message(gpointer data,	     gint source,	     GdkInputCondition condition) {  char *msg_buff=NULL;  size_t len;    gdk_input_remove(target_tag);  len=0;  msg_buff=NULL;  udp_recv_message(udp_con,&msg_buff,&len);      if (len>0) {	msg_data_t msg;	init_message_data(&msg);	dbg_out("Message arrive\n");	parse_message(&msg,msg_buff,len);	free(msg_buff);	msg_buff=NULL;	ipmsg_dispatch_message(udp_con,&msg);	release_message_data(&msg);      }  dbg_out("Add socket:%d\n",udp_con->soc);  target_tag=gdk_input_add(udp_con->soc,GDK_INPUT_READ,read_message,NULL);}intipmsg_send_broad_cast(const udp_con_t *con,const char *msg,size_t len){  if ( (!con) || (!msg) )    return -EINVAL;  userdb_send_broad_cast(con,msg,len);  hostinfo_send_broad_cast(con,msg,len);}intinternal_extend_memory(void **buff_p,size_t new_size,size_t orig_size,gboolean is_clear) {  void *new_buff;  void *orig_buff;  if ( (!buff_p) || (!(*buff_p)) )    return -EINVAL;  orig_buff=*buff_p;    new_buff=malloc(new_size);  if (!new_buff)    return -ENOMEM;  if (is_clear)    memset(new_buff,0,new_size);  memmove(new_buff,orig_buff,orig_size);  free(orig_buff);  *buff_p=new_buff;  return 0;}intcreate_lock_file(void){  int fd;  int rc;  fd=open(IPMG_LOCK_FILE,O_RDWR|O_EXCL|O_CREAT,(S_IRUSR|S_IWUSR));  if (fd<0) {    syslog(LOG_ERR|LOG_USER,"lock file(%s) already exist\n",IPMG_LOCK_FILE);    fd=open(IPMG_LOCK_FILE,O_RDWR);    if (fd<0)      return -errno;  }  rc=flock(fd,LOCK_EX|LOCK_NB);  if (rc<0)    return -errno;  return 0;}intrelease_lock_file(void){  int fd;  int rc;  fd=open(IPMG_LOCK_FILE,O_RDWR);  if (fd<0)    return -errno;  rc=flock(fd,LOCK_UN);  if (rc<0)    return -errno;  rc=unlink(IPMG_LOCK_FILE);  if (rc<0)    return -errno;  return 0;}intinit_ipmsg(void){  int rc;  char *cwd;    cwd=getenv("HOME");  if (cwd)    rc=chdir(cwd);  else {    cwd=getenv("TMPDIR");    if (cwd)      rc=chdir(cwd);    else      rc=chdir("/tmp");  }  if (rc)    return -errno;  logfile_init_logfile();  init_message_info_manager();  init_sound_system(PACKAGE);  memset(&con,0,sizeof(udp_con_t));  rc=udp_setup_server(&con,hostinfo_refer_ipmsg_port(),hostinfo_get_ipmsg_system_addr_family());  if (rc<0)    return rc;  rc=udp_enable_broadcast(&con);  if (rc<0)    return rc;  udp_con=&con;  dbg_out("Add socket:%d\n",udp_con->soc);  target_tag=gdk_input_add(udp_con->soc,GDK_INPUT_READ,read_message,NULL);  ipmsg_send_br_entry(udp_con,hostinfo_get_normal_send_flags());  return 0;}voidcleanup_ipmsg(void){  logfile_shutdown_logfile();  hostinfo_cleanup_hostinfo();  dbg_out("UI Thread ended\n");  cleanup_sound_system();  ipmsg_send_br_exit(udp_con,hostinfo_get_normal_send_flags());  udp_release_connection(udp_con);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -