summaryrefslogtreecommitdiffstats
path: root/fastos/src/vespa/fastos/unix_ipc.h
blob: 35e77e11cb216b9b6c8ac791413a8280fbcdf2de (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "app.h"
#include "process.h"
#include "thread.h"
#include <poll.h>

class FastOS_RingBuffer;

class FastOS_UNIX_IPCHelper : public FastOS_Runnable
{
private:
    FastOS_UNIX_IPCHelper(const FastOS_UNIX_IPCHelper&);
    FastOS_UNIX_IPCHelper& operator=(const FastOS_UNIX_IPCHelper&);

protected:
    FastOS_Mutex  _lock;
    volatile bool _exitFlag;
    FastOS_ApplicationInterface *_app;

    FastOS_UNIX_Process::DescriptorHandle _appParentIPCDescriptor;

    int _wakeupPipe[2];

    bool DoWrite (FastOS_UNIX_Process::DescriptorHandle &desc);
    bool DoRead (FastOS_UNIX_Process::DescriptorHandle &desc);
    bool SetBlocking (int fileDescriptor, bool doBlock);
    void BuildPollCheck (bool isRead, int filedes, FastOS_RingBuffer *buffer, bool *check);
    void BuildPollArray(pollfd **fds, unsigned int *nfds, unsigned int *allocnfds);
    bool SavePollArray(pollfd *fds, unsigned int nfds);
    void PerformAsyncIO (void);
    void PerformAsyncIPCIO (void);
    void BuildPollChecks(void);
    void DeliverMessages (FastOS_RingBuffer *buffer);
    void PipeData (FastOS_UNIX_Process *process, FastOS_UNIX_Process::DescriptorType type);
    void RemoveClosingProcesses(void);

public:
    FastOS_UNIX_IPCHelper (FastOS_ApplicationInterface *app, int appDescriptor);
    ~FastOS_UNIX_IPCHelper ();
    void Run (FastOS_ThreadInterface *thisThread, void *arg) override;
    bool SendMessage (FastOS_UNIX_Process *xproc, const void *buffer, int length);
    void NotifyProcessListChange ();
    void AddProcess (FastOS_UNIX_Process *xproc);
    void RemoveProcess (FastOS_UNIX_Process *xproc);
    void Exit ();
};