小编Dav*_*har的帖子

在socket编程中,多进程(线程)中accept()同一个监听socket可以吗?

IE

  1. 在父进程中打开监听套接字
  2. 在child1,child2,child3...中调用epoll_wait(listening_socket)
  3. 如果有连接请求,请在每个子进程中调用accept

sockets pthreads

2
推荐指数
1
解决办法
3980
查看次数

循环通过NSMutableArray

我有一个NSMutableArray,我加载了不同的对象(类).

现在我需要遍历数组并进入类以进行进一步操作.

我正在尝试这种方法......

for (id obj in allPointsArray)   
  {
/////   this is where i need to bring the obj into a class to work with
    NSInteger loc_x = obj.x_coord;
    NSInteger loc_y = obj.y_coord;
  }
Run Code Online (Sandbox Code Playgroud)

但我无法理解实际上将类从数组中移出并将其放入可用对象中.

x_coord和y_coord在存储在数组中的所有对象之间是通用的.

谢谢大家的帮助

objective-c nsmutablearray

2
推荐指数
1
解决办法
7662
查看次数

如何让MySQL在一段时间内运行查询?

我正在创建一个Web应用程序,其中需要处理表的每一行.我正在为每个表行生成一个子PHP进程.我正在实现一个安全机制,所以如果PHP进程被中断处理一行,将产生一个新的PHP进程来处理所述行.为此,我将创建一个新表,其中所有PHP进程每10秒左右检查一次.我需要MySQL删除所有尚未检查5分钟或更长时间的行,因此我的应用程序将知道创建一个新的PHP子进程来处理该行.

我知道有可能让MySQL在一段时间内运行查询,但我不知道如何.

〜输入stackoverflow~


编辑:我希望学习如何做到100%MySQL.有没有办法设置MySQL每小时​​运行一次查询,或者每天或特定时间运行查询?

php mysql

2
推荐指数
2
解决办法
7352
查看次数

malloc的问题

我正在尝试在我的代码中应用malloc,但仍然有问题,有一个错误说:"请求成员'id'在非结构或联合的东西中".

我想要做的是使用malloc而不是数组..并将结构存储在每个索引中,我尝试了array [i] - > id,但是我的文本文件中存储了一堆垃圾字符.我也增加了我并没有使用循环,因为用户可能只输入一次...这是我的代码:

#include<stdio.h>
#include<stdlib.h>
struct studentinfo{
       char id[8];
       char name[30];
       char course[5];
}s1;
main(){
    int i=0;
    FILE *stream = NULL;
    stream = fopen("studentinfo.txt", "a+");    
    struct studentinfo *array[50];

    array[i] = (struct studentinfo*) malloc(sizeof(struct studentinfo));
       printf("Enter Student ID: ");
       scanf("%s", array[i].id);
       fflush(stdin);
       printf("Enter Student Name: ");
       gets(array[i].name);
       fflush(stdin);
       printf("Enter Student Course: ");
       scanf("%s", array[i].course);

       fprintf(stream, "\n%s,\t%s,\t%s", array[i].id, array[i].name, array[i].course);
       i++;
       fclose(stream);
       free(array);
    getch();
}
Run Code Online (Sandbox Code Playgroud)

希望你能帮助我...在此先感谢:)

c malloc

1
推荐指数
1
解决办法
392
查看次数

kCFStreamPropertySocketSecurityLevel到kCFStreamSocketSecurityLevelNegotiatedSSL导致连接到Java的OSStatus errSSLXCertChainInvalid(-9807)

我有一个简单的Java服务器,它使用自签名证书来标识我用keytool创建的自己:

  System.setProperty("javax.net.ssl.keyStore", "../../pki/z-keystore.jks");
  System.setProperty("javax.net.ssl.keyStorePassword", "ZZZZZZ");
  System.setProperty("javax.net.debug", "all");

  ServerSocketFactory serverSocketFactory = SSLServerSocketFactory
    .getDefault();
  ServerSocket serverSocket = serverSocketFactory
    .createServerSocket(8443);

  System.out.println("Waiting for connections on 8443");
  final AtomicInteger nextSocketId = new AtomicInteger(); 
  while (true) {
   final Socket socket = serverSocket.accept();
   new Thread(new Runnable() {
    @Override
    public void run() {
     final int socketId = nextSocketId.getAndIncrement();

     try {
      System.out.println("Received connection from socketId: " + socketId);
      BufferedReader bufferedReader = new BufferedReader(
        new InputStreamReader(socket.getInputStream()));
      PrintWriter printWriter = new PrintWriter(
        new OutputStreamWriter(socket.getOutputStream()));

      for (String line = bufferedReader.readLine(); line != …
Run Code Online (Sandbox Code Playgroud)

java ssl cocoa cocoa-touch cfnetwork

1
推荐指数
1
解决办法
4252
查看次数

需要将以下FORTRAN代码转换为C++

我是一个非常差的程序员,我得到了一个程序,据说可以帮助我的空气动力学hw.但它在fortran,我试图使用MATLAB来运行这个程序.将它转换为matlab语言的任何帮助都能理解?(优选c ++)

      program joukow
c

c   computes joukowski airfoil and finds pressure coefficient

c   currently set up for symmetric airfoil with sharp trailing edge

c   and chord length equal to one.

c   profile is written onto prof.dat and cp onto cp.dat

c      implicit real*8(a-h,o-z)

      complex z,zeta,cw
      dimension uz(100),vz(100),xi(100),eta(100),cp(100)
      dimension xout(100),yout(100)
         open(unit=8,file='prof.dat',status='unknown')
         open(unit=9,file='cp.dat',status='unknown')
      b=1.d0
      write(6,98)
      format(2x,'input the radius of the a-circle in z plane')
      read(5,99)a
      format(f10.0)
      xl=2.*a-1.+1./(2.*a-1.)

c      xl=a+1./a

c      chord=2.*xl

      chord=2.+xl
      del=a-b

c      del =0.1d0
      do 50 i=1,100
      ri=i
      theta=6.2832d0*ri/101.d0 …
Run Code Online (Sandbox Code Playgroud)

c++ matlab fortran

0
推荐指数
1
解决办法
1103
查看次数

为什么我的UIView表现得很迟钝?

我有一个UIView控制器,它有一个背景图像和一个UIWebView设置,可以通过autoresizeResizingMask属性自动调整方向更改.它在模拟器中运行平稳,但在设备上预览时非常缓慢.

我很少使用Web视图CALayer来创建边框和阴影,当我评论这些部分时,它运行得更顺畅.当玩CALayer(我怀疑)或者我是否错误地实现了这些部分时,这只是该课程的标准吗?

这是视图确实加载方法

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {

    NSLog(@"Web project View Controller");
    [super viewDidLoad];

    UIImageView *bg = [[UIImageView alloc] initWithFrame:self.view.bounds];
    bg.contentMode = UIViewContentModeCenter;
    bg.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    bg.image = [UIImage imageNamed:@"fuzzyhalo.png"];
    [self.view addSubview:bg];


    projectView = [[UIWebView alloc] initWithFrame:self.view.bounds];
    projectView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    projectView.layer.backgroundColor = [UIColor blackColor].CGColor;

    projectView.layer.shadowColor = [UIColor blackColor].CGColor;
    projectView.layer.shadowOpacity = 1.0;
    projectView.layer.shadowRadius = 5.0;
    projectView.layer.shadowOffset = CGSizeMake(0, 0);  

    projectView.layer.borderColor …
Run Code Online (Sandbox Code Playgroud)

cocoa-touch uiwebview calayer uiview

0
推荐指数
1
解决办法
247
查看次数

Objective C iPhone开发,保存和检索NSMutableArray

我是iPhone开发新手,我正在使用XCode 4.2我试图保存一个NSMutable数组,这样当我关闭应用程序并重新打开它时,数据仍然在那里我使用这两个函数:

-(void)saveData{
    [NSKeyedArchiver archiveRootObject:[data copy] toFile:[self dataFilePath]];
}
- (void)loadData
{
    data = [NSKeyedUnarchiver unarchiveObjectWithFile:self.dataFilePath];
}
Run Code Online (Sandbox Code Playgroud)

但是我发现了两个主要问题:1-当我切换视图并返回时,当我完全退出应用程序时(即我双击主按钮并将其从正在运行的应用程序列表中删除)数据消失了数据也没有被删除

我发现我可以用这两种方法的NSMutableArray:writeToFile和initWithContentsOfFile ,但我不知道在哪里可以打电话给他们(是,当我将项目添加到UITableView中的?viewDidLoad?

有人可以给我一个示例代码吗?

提前致谢

iphone objective-c nsmutablearray ios xcode4.2

0
推荐指数
1
解决办法
698
查看次数