コード例 #1
0
/*-------------------------------------------------------------------------*\
* object:send() interface
\*-------------------------------------------------------------------------*/
int buffer_meth_send(lua_State *L, p_buffer buf) {
    int top = lua_gettop(L);
    int err = IO_DONE;
    size_t size = 0, sent = 0;
    const char *data = luaL_checklstring(L, 2, &size);
    long start = (long) luaL_optnumber(L, 3, 1);
    long end = (long) luaL_optnumber(L, 4, -1);
#ifdef LUASOCKET_DEBUG
    p_timeout tm = timeout_markstart(buf->tm);
#endif
    if (start < 0) start = (long) (size+start+1);
    if (end < 0) end = (long) (size+end+1);
    if (start < 1) start = (long) 1;
    if (end > (long) size) end = (long) size;
    if (start <= end) err = sendraw(buf, data+start-1, end-start+1, &sent);
    /* check if there was an error */
    if (err != IO_DONE) {
        lua_pushnil(L);
        lua_pushstring(L, buf->io->error(buf->io->ctx, err)); 
        lua_pushnumber(L, (lua_Number) (sent+start-1));
    } else {
        lua_pushnumber(L, (lua_Number) (sent+start-1));
        lua_pushnil(L);
        lua_pushnil(L);
    }
#ifdef LUASOCKET_DEBUG
    /* push time elapsed during operation as the last return value */
    lua_pushnumber(L, timeout_gettime() - timeout_getstart(tm));
#endif
    return lua_gettop(L) - top;
}
コード例 #2
0
ファイル: LaserdockDevice.cpp プロジェクト: Grix/ildagen
bool LaserdockDevice::runner_mode_run(bool v) {
    uint8_t request[] = {0xC0, 0x09, v? (uint8_t)0x01: (uint8_t)0x00};
    uint32_t rlen = 4;
    uint8_t response[64];
    bool r =  sendraw(d->devh_ctl, request, rlen, response);
    return r;
}
コード例 #3
0
ファイル: job.c プロジェクト: aaniket/Computer-Networks
int main(){
	int sfd,nsfd,port,clength,cnt=0;
	int port1=14112;
	struct sockaddr_in s_addr,c_addr;
	char buffer[1024];
	sfd=socket(AF_INET,SOCK_STREAM,0);
	assert(sfd>=0);
	
	s_addr.sin_family=AF_INET;
 	//s_addr.sin_addr.s_addr=INADDR_ANY;//INADDR_ANY binds to all availible interfaces
	s_addr.sin_addr.s_addr=inet_addr("127.0.0.1");
	s_addr.sin_port=htons(port1);

	bind(sfd,(struct sockaddr_in *)&s_addr ,sizeof(s_addr));

	listen(sfd,5);
	printf("Not connected to any interviever ...\n");

	struct pollfd fds[4];
	int n=0;
	while(1){
			char list[1024];
			int lval=0;
			nsfd=accept(sfd,(struct sockaddr *) &c_addr,&clength);
			fds[n].fd=nsfd;
			fds[n].events=POLLIN;
			n++;
			int ret=poll(fds,n,timeout);
			if(ret>0){
				int i=0;
				for(i=0;i<n;i++){
					if(fds[i].revents&POLLIN){
						buff[0]='/0';
						int n=read(fds[i].fd,buff,sizeof(buff));
						buff[n]='/0';
						printf("buffer %s\n",buff );
						sprintf(list,"%s",buff);
						lval+=n;
					}
				}

				list[lval]='/0';
				printf("fd number and score list \n %s \n",list );
				//sleep(3);
				sendraw();
			}
	}
	return 0;

}
コード例 #4
0
ファイル: LaserdockDevice.cpp プロジェクト: Grix/ildagen
bool LaserdockDevice::runner_mode_load(LaserdockSample *samples, uint16_t position, uint16_t count) {
    uint8_t * request =(uint8_t *) calloc(sizeof(uint8_t), 64);

    request[0] = 0xC0;
    request[1] = 0x08;

    uint16_t * pos = (uint16_t *)(request+2);
    uint16_t * cnt = (uint16_t *)(request+4);
    *pos = position;
    *cnt = count;

    memcpy(request+6, samples,  sizeof(LaserdockSample) * count);

    uint32_t rlen = 64;
    uint8_t response[64];
    bool r =  sendraw(d->devh_ctl, request, rlen, response);

    return r;
}